Is there a way to avoid variables swtiching to 0 after a subroutine has been called?
I’ve got a subroutine that needs to be called multiple times within the program and I am using a variable to count for a base frame changes.
The problem is the count reset to 0 every time the routine is called again, is there a way to use global variables or something or just stop them being reset?
Every time a routine is called, its variables reset by design. This applies to main routine as well as subroutines.
One option is use component property, which can act as global variable. So in this example I have a counter property of type int, that is set in Main Routine and used in While loop. Just for demonstration purposes, I decrement the value of my counter property in the called subroutine.
So the sequence runs 3 times and the variable isn’t reset each time.
I’ll look into component properties as a way to create global variables, it would help simplify the programs. I like being able to cut it up into sub routines so the main one isn’t 100s of lines long so keeping the logic in subroutines but the variables in the main would keep it tidy.