Author Topic: Global Variables example  (Read 4799 times)

VetalYA

  • Guest
Global Variables example
« 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 contain ugly examples )


Thank you in advance.

VetalYA

  • Guest
Re: Global Variables example
« Reply #1 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;
« Last Edit: October 30, 2011, 12:27:18 pm by VetalYA »

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: Global Variables example
« Reply #2 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.

 

© Liberty Unleashed Team.