• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Why do locals = MUI ?

Status
Not open for further replies.
Level 29
Joined
Jul 29, 2007
Messages
5,174
Now I wonderd about this for some time.
Im not really good at programming (more like a total noob), but I think I got how they work.
Each function is a little box of code, so the locals get set every time the box is activated right ?

So why when 2 units do something at the same time it won't set the local to only 1 of them ?

And why, say, when a unit casts a spell and the triggers work, then another unit casts that spell too while the first didn't finish it, why wouldn't it reset the locals and then set them to the new one while destroying the spell to the first one ?
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
It's the way the run-time stack works.

When a function is called, this is what happens:
first, all parameters a function "takes" are loaded into the memory.
Then some other things happen (it's not important here), and finally the local variables are created for the function.
When this is done, the function will "run" and do everything it's supposed to do, such as calculating a cosinus (in case of a Cosinus function call).
Everytime a function is called, this procedure will repeat, thus it's possible to have the same function in the memory for multiple times, all having their OWN separate local variables.
However: there are also global variables. These are declared "globally" and can be accesed from ANY function. This also means any function can use them or change them. But if there are multiple instances of the same function running, they will all change the SAME global variable instead of their own declared local variables.

Not sure if this explanation is clear (or correct), but it's more or less what happens.
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
Nothing can change locals in a function but thread itself
so
local integer i = 100
call TriggerSleepAction(999999999999)

i will be 100 after 9999999999 seconds no mater what you do
(another thread of same function can't change others too
thread: ... something like you run a function you run a unique thread >.< ban me pls)
 
Level 3
Joined
Dec 28, 2007
Messages
46
Basically when a function is called the stack reads the function and makes separate copies of the all the locals needed for only each instance of the functions for them to use themselves.
 
Status
Not open for further replies.
Top