I have a trigger, which uses a global vaiable. This trigger's action have some cycles, so it need some time to be performed.
Is it possible, that another instance of the action will start to perform before the first instance ended?
I just want to know, is it safe to use global variables? I scared about two or more parallell working functions could use the same global variable at the same time. It will cause wrong results of the calculations.
So, is the situation real? Or functions are always work sequentially, even if the game start alot of them in one moment?
You can have this trigger run a thousand times simultaneously and there is no way they would interfere with each other. Even though they all access GlobalVariable.
That's because there is no wait command between the actions that use the variable. That means they happen right after each other. No other trigger will have a chance to change it beforehand.
Now it's different. It can very well be that, during the 10 seconds between the actions, the GlobalVariable is changed by another trigger. And this will affect the trigger.
So you basically have to watch out for a few things:
1) Use local variables where you can. Local variables are owned by the trigger instance, and every trigger instance will have it's own copy.
2) If you need the content of a global variable AND you need to be sure it's still the same after some time, then make a local variable and copy over the content of the global one.
3) You shouldn't have a lot of different triggers that can change a global variable's value. Generally you don't need to.
I know for sure that 2 instances of this function will start at the same moment by different players. Will they interfere by some multithread way, or functions without wait commands never interfere?
As long as there is no wait, they will never interfere. Although they are running in parallel, they are actually queued. The first one that is called is run first, but its very fast, so it'll seem as if it's parallel. Like s3rius said, it's probably better to copy the global variable into a local variable, then use the local variable instead. Theres less risk of the thing bugging on you that way.
I have a trigger, which uses a global vaiable. This trigger's action have some cycles, so it need some time to be performed.
Is it possible, that another instance of the action will start to perform before the first instance ended?
I just want to know, is it safe to use global variables? I scared about two or more parallell working functions could use the same global variable at the same time. It will cause wrong results of the calculations.
So, is the situation real? Or functions are always work sequentially, even if the game start alot of them in one moment?
This very much depends on how you're using the variable, but it can very well happen.
Let's say the trigger looks like this:
You can have this trigger run a thousand times simultaneously and there is no way they would interfere with each other. Even though they all access GlobalVariable.
That's because there is no wait command between the actions that use the variable. That means they happen right after each other. No other trigger will have a chance to change it beforehand.
Now it's different. It can very well be that, during the 10 seconds between the actions, the GlobalVariable is changed by another trigger. And this will affect the trigger.
So you basically have to watch out for a few things:
1) Use local variables where you can. Local variables are owned by the trigger instance, and every trigger instance will have it's own copy.
2) If you need the content of a global variable AND you need to be sure it's still the same after some time, then make a local variable and copy over the content of the global one.
3) You shouldn't have a lot of different triggers that can change a global variable's value. Generally you don't need to.
What if I don't have a Wait command in my function, but the cycle is large? I's like:
I know for sure that 2 instances of this function will start at the same moment by different players. Will they interfere by some multithread way, or functions without wait commands never interfere?
@Zolden: Go
As long as there is no wait, they will never interfere. Although they are running in parallel, they are actually queued. The first one that is called is run first, but its very fast, so it'll seem as if it's parallel. Like s3rius said, it's probably better to copy the global variable into a local variable, then use the local variable instead. Theres less risk of the thing bugging on you that way.
Got it, thanx for explanations.