Quick question about a variables scope...

[lua]local foo

function setFoo

foo = “goo”

end[/lua]

Hi,
Could someone tell me if in the above code if im setting the local variable foo to “goo” or if I’m setting a globally accessible variable to “goo”

Thanks
Aidan [import]uid: 102413 topic_id: 25745 reply_id: 325745[/import]

You are setting the “local foo” defined just above it to “goo”. If there is also a global “foo”, it won’t be accessed from there because the local version is what is in scope when that assignment happens.

[import]uid: 19626 topic_id: 25745 reply_id: 104111[/import]

Super, Thanks Rob that makes sense.

So if it just looked like this…

function setFoo  
   
foo = "goo"  
   
end  

… Would I be setting a global variable called “foo” to “goo”

Thanks
Aidan [import]uid: 102413 topic_id: 25745 reply_id: 104165[/import]

Yep [import]uid: 19626 topic_id: 25745 reply_id: 104207[/import]