Register  |  FAQ  |  Search  |  Memberlist  |  Usergroups  |  Log in 
Reply to topic
 Scope of variables 
npantic


Joined: 12 Nov 2007
Posts: 19
Reply with quote
What is the scope of variables inside Awakening ? If i define variable in one script, can other scrip access its value?
Is every defined variable Global exept those marked Local?
View user's profile Send private message
  
Vincent


Joined: 25 Dec 2006
Posts: 296
Reply with quote
Quote:
What is the scope of variables inside Awakening ? If i define variable in one script, can other scrip access its value?

You can access other Script's variable, but it's exection order dependent.

For example:

Script1 with codes:
Code:
testNum=8
local testLocal=9


Script2 with codes:
Code:
print(testNum,testLocal)


do Script1, do Script2, output result: 8 nil
do Script2, do Script1, output result: nil nil

Quote:
Is every defined variable Global exept those marked Local?

Yes, in LUA, whether define variable in a function, or in global scope, you need marked 'local' for Local Variable; variables without 'local' marked are all Global.
View user's profile Send private message
  
npantic


Joined: 12 Nov 2007
Posts: 19
Reply with quote
Thanx for explanations... it seems clear. If i will in problem about this I will ask Very Happy
View user's profile Send private message
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic