Goto or jump functions
-
Okay I can say that I understand it to a certain extend now.
Rn I wrote a function that is my Main Game Engine. This Engine can be extended and improved by altering the function itself and will start after setting the needed Parameters in a main menu.
Here is what I learned the last time I used them:
If I want to Improve the Engine, every Variable that is used in the function itself must be determined in a Library before it is used in the function. Otherwise the compiler tells me that the Variable doesn't exist.
On the other side that means every Variable that's been defined inside of a function will Vanish after the Function is being executed. They only exist to work for the function
-
@Mechanical So variables can be local or global. As you say variables that are declared within a function are local to it and will cease to exist outside of the function. Variables declared outside of a function are global and they will persist even after the function has exited.
-
@pianofire but with the next update there will changes right?
-
@petermeisenstein There will be a change to the way that parameters are passed to functions. Global and local variables will remain the same.
-
@pianofire sooo, practically I need to change Syntax when the new update rolls out? Or does it stay the same on the frontend?
-
@Mechanical There was some confusion about whether parameters were being passed to functions by reference or by value. To clarify the situation the default is now by value and if you want to pass by reference you will need to add "ref" in front of the parameter (from the next patch)
-
@pianofire but it wont be possible for variables declared "new" in your function so a variable who is only declared inside your function
-
@petermeisenstein Sorry I don't understand the question
-
@pianofire So here is an example
function()
my_variable=1
return voidCan i use my_variable outside this function
-
@petermeisenstein So if you declare the variable outside of the function it becomes global and can be used anywhere:
int my_variable = 0 function test() my_variable=1 return void test() print(my_variable) // value will now be 1
-
@pianofire Ok thanks