Scripts / How to pass a variable to a lua al other lua ?

Author
Message
Extaziel
9
Years of Service
User Offline
Joined: 1st Apr 2015
Location: France
Posted: 3rd Apr 2015 10:27
Hello, sorry i m talk english very bad, but my issue is simple.

Is it possible put a value to a variable in a lua and get it back value in another lua ?

Ty
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 3rd Apr 2015 10:51
yes very simple actually, if you mean can you have a variable in one script and call it in another.

I will demonstrate

script one will declare a variable:



Now for script 2 which we will call the global variable from script 1



Hope that helps

simple breakdown:
unless declared Local then all scripts can access the variable as it will be global
PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz
Extaziel
9
Years of Service
User Offline
Joined: 1st Apr 2015
Location: France
Posted: 3rd Apr 2015 10:56
Yea thnaks very much

Good day for you
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 3rd Apr 2015 12:32
glad i could help
PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz
Extaziel
9
Years of Service
User Offline
Joined: 1st Apr 2015
Location: France
Posted: 3rd Apr 2015 13:19 Edited at: 3rd Apr 2015 13:26
I have another question, for this script :




If soldier dead with "one shoot" variable agro is not set, why ?, and solution ?
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 3rd Apr 2015 13:49 Edited at: 3rd Apr 2015 13:55
i would have to guess that it would be the AI script destroying entity before this script could update the agro, does it work when not one shot kill?

and by the way you dont need

local getVar = Agro

that getVar was just my example of a local variable calling the value of a global if that makes sense, your script will still access the Agro global without anything having to call it first

example, script 2 could be as such:



Edit:

I am far from a good coder here I just play around but one way around this would be possibly to get the entity number when you placed it in the editor (highlight it and it will display (e) number in bottom left corner) and use a separate script that checks to see if the entity has been destroyed or not (not even sure if that's possible).

I am hoping that smallg or someone who can Code could chime in here with a possible solution
PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz
Extaziel
9
Years of Service
User Offline
Joined: 1st Apr 2015
Location: France
Posted: 3rd Apr 2015 13:55 Edited at: 3rd Apr 2015 13:59
... i m bad in english

i would have to guess that it would be the AI script destroying entity before this script could update the agro, does it work when not one shot kill?

If is not one shoot kill, is it OK, all soldier go fight, if is one shoot : nothing.

that getVar was just my example of a local variable calling the value of a global if that makes sense, your script will still access the Agro global without anything having to call it first

I m not sure good understand, a lot of soldier have this scipt, if i attack one, all soldier come in fight except one shoot kill.
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 3rd Apr 2015 14:03
try this:



added Agro = 1 to an exit function for the script
PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz
Extaziel
9
Years of Service
User Offline
Joined: 1st Apr 2015
Location: France
Posted: 3rd Apr 2015 14:31
Good job is OK


Big thanks

latest question : is possible set agro = 1 if player shoot with weapon but no touch ?
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 3rd Apr 2015 14:45 Edited at: 3rd Apr 2015 14:47
not sure and out of time tonight to play around sorry, but something along the lines of this:


AIGetEntityHeardSound(EntObjNo)

not sure but try adding this:

PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz
Extaziel
9
Years of Service
User Offline
Joined: 1st Apr 2015
Location: France
Posted: 3rd Apr 2015 14:51
No don t works.

Login to post a reply

Server time is: 2024-12-21 14:03:20
Your offset time is: 2024-12-21 14:03:20