Javascript equivalent of @inc

I 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''?


Well the best answer I can make on my own is pretty long.

   squiffy.set("health", squiffy.get("health") + 1);

Oh well.


Yeah; 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.


You 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!


Note 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.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums