Liberty Unleashed

Scripting => Script Help => Topic started by: VetalYA on October 30, 2011, 11:32:04 am

Title: Global Variables example
Post by: VetalYA on October 30, 2011, 11:32:04 am
I need to use global variables, can some one give me an example ?

(I ask it here, because  http://squirrel-lang.org/doc/squirrel3.html#d0e599 (http://squirrel-lang.org/doc/squirrel3.html#d0e599) contain ugly examples )


Thank you in advance.
Title: Re: Global Variables example
Post by: VetalYA on October 30, 2011, 12:23:53 pm
Ok, i understand how to create them.

Its simply
Code: [Select]
g_myGlobalVar <- 234;//at the top of file
g_myGlobalVar1 <- "my value";//at the top of file


function onServerStart()
{
print( "My own global variable:  " + g_myGlobalVar);
print( "My own global variable :  " + g_myGlobalVar1);
return 1;
}

They have to be declared like this example:

Code: [Select]
g_YourVarName <- your_value;
Title: Re: Global Variables example
Post by: Thijn on October 30, 2011, 02:27:04 pm
It doesn't need to be at the top of your file btw, Declaring them in any function and then calling them somewhere else works just fine. Thats where global variables are for in the first place.