Pre and post Incremental operators in variables?


#1

I’m trying to increment the value of a variable by 1 each time a “plus” button is pressed and decrease it by the same amount when a “minus” button is pressed, and then printing it to a text.

I know that you can tell Axure to update the variable value from a text value, but that is just… SO unpractical. Is it really the case that Axure doesn’t support pre and post increment operators?

My biggest problem that I’m having right now is that I wanted to keep the text in one single text box, like “You have now x apples”, where x would be substituted by the variables value using something like “variableValue++”. In order to update the variable from a text object I need to separate the text in 3 parts (one being only for the variable value). It doesn’t even accept the verbose version of it like “variableValue = variableValue + 1”.

Why is that? Can we have that feature?.. It has so many math operators, would be nice to have this.


How to add to cart notification after clicked?
#2

Hi!

The verbose form of incrementing is supported. For instance, your “plus” button could say:

OnClick
  Set text of (widget) "counter" to (value) [[Target.text + 1]]

…no global variables required. Similarly, if you wanted to increment the text in a widget by clicking the widget itself, you could say:

OnClick
 Set text of (widget) This to (value) [[This.text + 1]]

If you need to access properties of widget that is neither the target of the command or the receiver of the event, you’d use a local variable where Target or This above sits.

The global variable “varName” can be incremented with:

Set varName to (value) [[varName + 1]]

You are correct that [[varName++]] is not supported.


#3

Thanks for the time you spent on the reply :slight_smile:

That’s a good approach, I’ll use that. But it still requires me to chop down the text if I’m not using a global variable. The advantage of using a global variable would be using the “rich text” option under the set text feature. Anyway, that is an elegant enough approach, thanks!