If/Then Statement issue; (actually setvariable / getvariable usage issue)

So the idea here is the int variable ‘object status’ is i+1 every time an external trigger is toggled. But im not sure that is actually happening as my if statement at the end never goes true.
Any ideas whats wrong with this code?
Any help would be greatly appreciated.

You’re not getting and setting variables properly. If objectstatus is supposed to be an int, then it should be stored as an int, not a string. If it was an int, you could plug it directly into “int equals” or “int +” nodes instead of using setprogramvariable and getprogramvariable.

There should be no need for setprogramvariable and getprogramvariable in this situation at all, and the way that you’re using them is simply not how variables work at all. When you get/set a variable with those nodes, it expects the name of a variable, like “OBJECTSTATUS”. But you’re not plugging in “OBJECTSTATUS”, you are plugging in the contents of OBJECTSTATUS, which is something like 1 or 2. Which means it is effectively trying to get a variable named “1” or “2” which doesn’t exist.

1 Like

ahhh interesting ok, ill retry that thanks!

Here is the fix, it works now for those interested.

Thanks alot @Phasedragon

If you hold ctrl while dragging a variable into the graph, you can set it directly without using setprogramvariable.

In addition, it looks like you have an old version of the SDK. If you update to the latest, setprogramvariable and getprogramvariable will have dropdowns that list all the variables available.

1 Like