Scripts / LUA Structure Questions

Author
Message
GoDevils
9
Years of Service
User Offline
Joined: 24th Sep 2014
Location: Arizona USA
Posted: 1st Feb 2015 21:24
Hi
I'm starting on a bigger script that involves the use of local variables and an indexed table.

I just want to make sure that I have the initial structure correct.



1) Is it proper to set up the local variables before the Init statement, or should this be part of the Init code?
2) By making the local declaration those variables are only available for use within this specific LUA script .. Correct?
3) Like the local variables, should the table ObjcontE1 be before the Init statement or part if the Init statement?
4) Are indexed tables global by nature or can they too be localized?

The above code is in the very early stages. Eventually it will move an object through a series of preset targets and at various speeds.

Thanks in advance

"There is no spoon"
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 2nd Feb 2015 10:08
I like to call my variables first and then put any
Settings (for arrays) into the init part, this is only
Really needed if you are referencing an object
Number though.
It'll work both ways though with your current
Code (although in the if statements you should
Remove those "locals ")

The table/array can be local, just set the initial
Declaration of it to local I.e. local ObjcoundE1 = {}

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
GoDevils
9
Years of Service
User Offline
Joined: 24th Sep 2014
Location: Arizona USA
Posted: 2nd Feb 2015 19:34
Thanks smallg

So i understand, local variables are only accessible within the LUA script in which they are declared as local. (yes?)

That said, can another script declare as local the same variable names?
and in so doing, the values for each set of local variables remains separate?

Thanks again as usual

"There is no spoon"
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 2nd Feb 2015 22:23
yes you are correct, that's the point of declaring them as local - so you can use the same variable name again elsewhere and not have the 2 interact in any way but yh they are only used inside that 1 script and any other scripts wouldnt "see" the variable at all
i dont actually know what happens if you have a local and a global with the same name... i assume the script with the local would only use the local value but not sure, i have always tried to make sure my locals are named differently to any globals

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11

Login to post a reply

Server time is: 2024-05-07 18:04:29
Your offset time is: 2024-05-07 18:04:29