Jump to content

Adding and subtracting to (& from) variables


Empfohlene Beiträge

I'm missing something simple here...

It ought to be ACTION [Set Variable]; Variable Name [My_Variable]; Value [$My_Variable + 1]

Or even ACTION [Set Variable]; Variable Name [My_Variable]; Value [+1]

But that doesn't seem to work for some reason...

Incrementing a counter should be a basic function, but I can't seem to figure out how to make it happen. I create the variable manually to ensure it is there. I let it increment, then go back to check... And it's gone. It's not even there with a zero value, it just isn't there at all!

Actually this seems to be a weird "feature" of the system. Refer to a variable in just one place and it vanishes. It seems that to have a variable recognised by the program you need to check its value somewhere that you aren't setting its value?

Anyway, point is, I would like to be able to increment values, and can't seem to find out how.

Simon

Link zu diesem Kommentar
Auf anderen Seiten teilen

Hi Andy.

It's gone 11 pm so I'll have another crack at it tomorrow evening. You said the syntax I'm using is correct? Is it  $My_Variable + 1 , or just +1, and if the former, should it have the spaces either side of the +? I've tried various combinations, but it's difficult to keep track of what I've tried!

The other question that is begged by this, is can I add two variables together?  [$Value_1 + $Value_2]

Link zu diesem Kommentar
Auf anderen Seiten teilen

Hello Simon,

I have prepared some examples for you. Please check out the enclosed layout:

Variablentest.mbp

It shows the most common value operations which are available in the event handling.

Variablentest.thumb.jpg.2703be6e4f00f4f2cdd6d83c13b7bb62.jpg

Please set your own values into the text fields where the text color is red. Then click to the switch at the right side.

The value will now be manipulated by the operations described in the lines below the 2 variable definition lines:

The left column describes the operation, the middle column shows the operation definition within the corresponding action definition, and in the right column, you see the opeation results after clicking to the switch.

Please study the corresponding actions within the one existing event definition in the event handling.
 

Generally, when calculating a variable, you can only specify the "variable" which will contain the result after completing the operation, and one additional value possibly combined with the operation to be realized:

[first input field]:          variable name, which is used as first operation value as well as for the result
[second input field]:    value or variable name, possibly combined with an operator, which will be calculated together with the first input field

Valid definitions:

[variableName1]  =  [value]                           direct value specification
[variableName1]  =  [$variableName2]          prefixed $ denotes, that the content of the variable with name variableName hast to be used
[variableName1]  =  [opValue]                       direct value specification with prefixed operation (without blanks!)
[variableName1]  =  [op$variableName2]      variable reference with prefixed operation

Invalid definitions:

[variableName1]  =  [op value]                      no blanks allowed between operation and value definition
[variableName1]  =  [$variableName2+$variableName3]    no combinations of values allowed

Realize the last (wrong) example by 2 actions:

[variableName1]  =  [$variableName2]
[variableName1]  =  [+$variableName3]


Many greetings
BahnLand

Link zu diesem Kommentar
Auf anderen Seiten teilen

Erstelle ein Benutzerkonto oder melde dich an, um zu kommentieren

Du musst ein Benutzerkonto besitzen, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen.

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde dich hier an.

Jetzt anmelden
×
×
  • Neu erstellen...