Eval in notifications

All about the past, current and future webteases and the art of webteasing in general.
---
Post Reply
OhXXXyes
Explorer
Explorer
Posts: 9
Joined: Sat Feb 24, 2018 8:57 am

Eval in notifications

Post by OhXXXyes »

Hello,

I've been trying to get an eval as the output of a notification but I can't get it to work.

So I created a notification, and the number on the notification is supposed to go up by the click of a button.

Example = Example + 1
Notification.get("notification").setTitle("Example")

Can somebody tell me what I'm doing wrong, of if this is even possible?

Thank you!
kerkersklave
Explorer At Heart
Explorer At Heart
Posts: 709
Joined: Sun Jul 06, 2014 2:11 pm
Gender: Male
Sexual Orientation: Open to new ideas!
I am a: Slave

Re: Eval in notifications

Post by kerkersklave »

"Example" is a string, that is, just the Text Example, if you want to use the variable named Example, remove the quotation marks.
OhXXXyes
Explorer
Explorer
Posts: 9
Joined: Sat Feb 24, 2018 8:57 am

Re: Eval in notifications

Post by OhXXXyes »

Thank you

so now i have:

Example = Example + 1
Notification.get("Notification").setTitle(Example)

But the notification remains unchanged on screen.
User avatar
eXquisite
Explorer
Explorer
Posts: 31
Joined: Sun Feb 06, 2022 1:32 pm
Sexual Orientation: Bisexual/Bi-Curious

Re: Eval in notifications

Post by eXquisite »

To me it looks correct. Are you sure you named your notification correctly, so it's called "Notification" (without quotation marks and with upper letter at the beginning)?

Edit: your variable "Example" is a constant, that's why you can't change it - rename it to "example". Any variable that's starting with upper case is a constant.

Code: Select all

var example = 0;
example++;
Notification.get("Notification").setTitle(example);
If you want to add text before the number use this code instead (replace "Score: " with what you want):

Code: Select all

Notification.get("Notification").setTitle("Score: " + example)
OhXXXyes
Explorer
Explorer
Posts: 9
Joined: Sat Feb 24, 2018 8:57 am

Re: Eval in notifications

Post by OhXXXyes »

I still seem to be doing something wrong. Edit: I am an idiot for skimming your message. The problem lies with the uppercase letter.

Rightnow im getting score: 1
But the score should be 0 still at that point.

Why did you put the "++" at the end there and what is the language called?
Ive learned alot already, despite the thing not working yet. So thank you both for the input!
kerkersklave
Explorer At Heart
Explorer At Heart
Posts: 709
Joined: Sun Jul 06, 2014 2:11 pm
Gender: Male
Sexual Orientation: Open to new ideas!
I am a: Slave

Re: Eval in notifications

Post by kerkersklave »

Uppercase does not make a difference for the variable. It is a convention to name constants with uppercase letters (all uppercase, not only the first), but that is just for readability. It is not a rule of Javascript.

If tested it, and the issue is, that EOS requires setTitle to be called with a String, not a number. That's why:

Code: Select all

var Example = 0
Notification.get("asd").setTitle(Example)
won't work.
But the following will:

Code: Select all

var Example = 0
Notification.get("asd").setTitle("" + Example)
++ is the increment operator in Javascript (and many other programming languages), x = x + 1 works just as well of course.
OhXXXyes
Explorer
Explorer
Posts: 9
Joined: Sat Feb 24, 2018 8:57 am

Re: Eval in notifications

Post by OhXXXyes »

That did it. Thanks.

It didn't help that I assumed I didn't need to call up the Notification each time, but it makes a lot of sense.
Post Reply