Variables are not recognized inside Function

Auto variable getter is making a mess in functions.
Here is my case.
v 5.3.195

  • Create a function with a Shape Painter as Parameter
  • Inside the function, change a number variable (example: an index), and create it through the Variables panel inside the function so they kept recognized in autocompletion
  • In a repeat loop, add 1 to the SP index
  • Then log in the console the result with a message like "index : "+ToString(Painter.index)

Result : the variable is updated but no message will show up in the console. It will be fully empty. It also breaks if you use the auto getter in Actions (try to draw a line using the auto getter for index, it will always be 0)

Note : it also breaks even if you create them outside the function, in the actual Shape Painter.

Workaround : using the good old “Variable” expression.

Code

Result and console

It’s not yet possible to declare variables in functions. What you are creating is probably a global variable. The new variable syntax doesn’t work in extensions, they appear in red unless there is a bug.

Can you give more details about your findings?

1 Like

The code you see is the one used in Function.

When it says i use undeclared variables, i use the Variables panel and create them, directly from the Action i put in the Function, like a Change Variable for example (it looks to locally create variables, so they can be shown in the Autocompletion system)

After that, i code like normal. Variables look to be recognized since i created them for this context, and they don’t appear red.

And no, it’s not a global variable since they are correctly shown in the inspector with correct values. But i can’t use them with the auto getter afterward.

For context. I tested this and at first I couldn’t find a variable screen inside a function until I realized it was object variables. You can open the object variable setup from within functions with the button within things like action events. I was able to add an object variable and use autocomplete but when adding the object variable to another value it caused the variable to be zero.

The object variable screen appears with all function types. Function, behavior and custom object but doesn’t seem to really work since (expect for custom objects) the objects don’t really exist inside a function. Although, even within a custom object it doesn’t work like a real setup screen.

1 Like