Author Topic: When you define a variable in one function, will you have to define it again?  (Read 635 times)

/title
For example, if I did %this = %that in the first function, will %this always equal %that? Or will I have to redefine it for every function?

Local variables (%this) are deleted at the end of their 'scope'. If you define a local variable inside of a function, it will only exist inside of that instance of running the function.

Global variables ($this) aren't deleted until the simulation ends or a user does so.

Typically, it's considered poor practice to use global variables liberally.

What otto said
You could also try passing the variables as arguments between different functions
Code: [Select]
function a()
{
    %var = "pie";
    b(%var);
}

function b(%var)
{
    %var.eat();
    echo(%var SPC "eaten");
}
If you typed a(); into console, the console would say "pie eaten"