Javascript equivalent of @inc
IFforClassroom
16 Feb 2023, 00:44I tried to use squiffy.set("health", +1);
in a function. It seemed to be working, until I noticed that "health" simply became 1 whenever this got activated. It doesn't actually increase. Is there a Javascript equivalent to Squiffy's "@inc''?
IFforClassroom
17 Feb 2023, 05:17Well the best answer I can make on my own is pretty long.
squiffy.set("health", squiffy.get("health") + 1);
Oh well.
mrangel
17 Feb 2023, 10:27Yeah; the get and set methods just retrieve or replace a Squiffy attribute; it's necessary to get the old value before setting the new one in two separate function calls.
You could do:
squiffy.ui.processText("{@health+=1}");
which is shorter to write, but less efficient.
IFforClassroom
17 Feb 2023, 23:24You could do:squiffy.ui.processText("{@health+=1}");
which is shorter to write, but less efficient.
Wait, wait, wait! ✋😲
Are you telling me, mrangel, that there is a simple way get around Squiffy's operator precedence and use it inline with Javascript ANY. TIME. I. WANT.
This is wonderful. That needs to show up somewhere in the Squiffy documentation.
Thank you!
mrangel
18 Feb 2023, 20:46Note that if you use processText
with blocks like {if
that would normally display text, it will return a string containing the results rather than outputting it directly. But for {@
that isn't usually a concern.