I'm having an issue with adding kill rewards in a defense map. The kills you get scale into the thousands, and you can kill anywhere up to 6 units in under a second's time, so I need a variable to block the trigger from running more than once when fired. I have created such a trigger.
The specific trigger runs once a player reaches 1500 kills, and triggers a boolean local variable to true when it fires, failing the conditions so that the trigger will not repeat. I have the conditions set to require that the local boolean variable be != true, and Player[playernumber] kills == 1500. The very first action in the trigger is flipping the boolean so it will be sure to fail conditions as quickly as possible.
However, the issue I'm having is that the trigger will fire more than once regardless, even if the boolean is set to true despite the conditions I set. The event is "Any Unit Dies," but should only run if the conditions are met.. I'm starting to get frustrated with it, haha.
Is there something I'm missing with this? Is there something extra I need to do for local variables to register or something? It's almost as if the variable I created doesn't exist.. I haven't tried a global variable, since I figured it was unnecessary for something that only happens once within the trigger.
I am not sure, if I understood your problem correctly.
You have a trigger, increasing a variable every time a unit dies
You have a kill reward for 1500 killed units, realized by adding a condition or if/then/else checking for the variable
As you approach 1500 killed units, if you kill multiple units in quick succession, you will receive the reward multiple times
To circumvent this, you added a local boolean variable, which is set to true at the start of the trigger and is checked in the trigger's conditions
Correct so far?
Well, in this case, the local boolean would be the problem. If you use a local variable, each execution of the trigger would have its own version of the boolean with no influence on each other. If the trigger triggers multiple times, they only set their separate booleans to true, but cannot check for the local booleans of the other trigger executions.
However, the firing multiple times is strange already. It would suggest, that multiple executions of the same trigger can run simultaneously, which, to my understanding, is not the case. Every trigger (and every function at all for that matter) is executed sequentially, it should not be possible for the reward to be executed multiple times, if done properly.
1) Move the Boolean variable into a global variable position, make it an array the size of the number of max players, and call it something like "Player_has_1500".
Then when that trigger happens, checking for == 1500, you also check that Player_has_1500[Killing Player] != True. And finally the first action of the trigger would immediately set Player_has_1500[Killing Player] = True.
That will take care of that... but also note that you should probably change the Condition for == 1500 to be >= 1500. If he killed 7 units at once it might skip 1500... and because of our boolean check it'll never run again anyway.
If this does nothing, then post a screenshot of the trigger.
If he killed 7 units at once it might skip 1500...
This is assuming again, that the SC2 engine is capable of executing 2 functions simultaneously, which is not the case. If one function starts, only this one function is active until it is finished or interrupted (for example by a wait or by a trigger event specifically caused by the function). Then, the next function is started.
If you kill 7 units "at once", the game will still kill them sequentially; it kills the first unit, starts the kill trigger, kills the 2nd unit, starts the kill trigger and so on. So, as long as you increment the variable in the same trigger, which executes the reward, there shouldn't be a problem at all.
So essentially what you guys are saying is that I need to create a global variable to keep this from happening?
What exactly are local variables used for, if they're used for anything at all? Is it constrained inside of the trigger only? The reason I'm confused is because if the trigger runs more than once, it shouldn't fire because the variable is already set to true.. so you're saying each fire is just a separate instance of the trigger?
I'm sure the global variable idea will work.. I just didn't want to create 5-6 global variables per player in the game, so I'll try the array idea you suggested. It may have to wait until tomorrow, due to the time of evening.
As in every programming language, local variables exist only within the scope of their declaration ( function, trigger or whatever ). They cease to exist outside of that scope. Global variables are global and can be accessed from any piece of code.
like Stragus said, your local variable is essentially destroyed after the trigger ends. If it is running each time a unit dies then your local variable is reset each time to its default at the beginning and will never hold and accurate value. A good rule of thumb is to never set conditions to include local variables.
So essentially what you guys are saying is that I need to create a global variable to keep this from happening?
What exactly are local variables used for, if they're used for anything at all? Is it constrained inside of the trigger only? The reason I'm confused is because if the trigger runs more than once, it shouldn't fire because the variable is already set to true.. so you're saying each fire is just a separate instance of the trigger?
I'm sure the global variable idea will work.. I just didn't want to create 5-6 global variables per player in the game, so I'll try the array idea you suggested. It may have to wait until tomorrow, due to the time of evening.
like my post said on your other thread (that was locked). Local Variables exists only in that one trigger instance. you definitely need a Global Variable. Arrays help with that =P
like my post said on your other thread (that was locked). Local Variables exists only in that one trigger instance. you definitely need a Global Variable. Arrays help with that =P
Going to try it out here shortly! Finishing up with dinner, then I'll give it a run and check it out with a global array.
Thank you all very much for your replies, and helping me to understand how SC2 handles local and global vars. I created a global and used that to check against for the kill rewards. Success!
I've learned a lot from this community. Maybe I'll upload my map once I complete it to try and sort of give back.
Greetings,
I'm having an issue with adding kill rewards in a defense map. The kills you get scale into the thousands, and you can kill anywhere up to 6 units in under a second's time, so I need a variable to block the trigger from running more than once when fired. I have created such a trigger.
The specific trigger runs once a player reaches 1500 kills, and triggers a boolean local variable to true when it fires, failing the conditions so that the trigger will not repeat. I have the conditions set to require that the local boolean variable be != true, and Player[playernumber] kills == 1500. The very first action in the trigger is flipping the boolean so it will be sure to fail conditions as quickly as possible.
However, the issue I'm having is that the trigger will fire more than once regardless, even if the boolean is set to true despite the conditions I set. The event is "Any Unit Dies," but should only run if the conditions are met.. I'm starting to get frustrated with it, haha.
Is there something I'm missing with this? Is there something extra I need to do for local variables to register or something? It's almost as if the variable I created doesn't exist.. I haven't tried a global variable, since I figured it was unnecessary for something that only happens once within the trigger.
Thank you for your time.
~VA
I am not sure, if I understood your problem correctly.
Correct so far?
Well, in this case, the local boolean would be the problem. If you use a local variable, each execution of the trigger would have its own version of the boolean with no influence on each other. If the trigger triggers multiple times, they only set their separate booleans to true, but cannot check for the local booleans of the other trigger executions.
However, the firing multiple times is strange already. It would suggest, that multiple executions of the same trigger can run simultaneously, which, to my understanding, is not the case. Every trigger (and every function at all for that matter) is executed sequentially, it should not be possible for the reward to be executed multiple times, if done properly.
Kueken is probably right.
1) Move the Boolean variable into a global variable position, make it an array the size of the number of max players, and call it something like "Player_has_1500".
Then when that trigger happens, checking for == 1500, you also check that Player_has_1500[Killing Player] != True. And finally the first action of the trigger would immediately set Player_has_1500[Killing Player] = True.
That will take care of that... but also note that you should probably change the Condition for == 1500 to be >= 1500. If he killed 7 units at once it might skip 1500... and because of our boolean check it'll never run again anyway.
If this does nothing, then post a screenshot of the trigger.
This is assuming again, that the SC2 engine is capable of executing 2 functions simultaneously, which is not the case. If one function starts, only this one function is active until it is finished or interrupted (for example by a wait or by a trigger event specifically caused by the function). Then, the next function is started.
If you kill 7 units "at once", the game will still kill them sequentially; it kills the first unit, starts the kill trigger, kills the 2nd unit, starts the kill trigger and so on. So, as long as you increment the variable in the same trigger, which executes the reward, there shouldn't be a problem at all.
@Kueken531: Go
@OneTwoSC: Go
So essentially what you guys are saying is that I need to create a global variable to keep this from happening?
What exactly are local variables used for, if they're used for anything at all? Is it constrained inside of the trigger only? The reason I'm confused is because if the trigger runs more than once, it shouldn't fire because the variable is already set to true.. so you're saying each fire is just a separate instance of the trigger?
I'm sure the global variable idea will work.. I just didn't want to create 5-6 global variables per player in the game, so I'll try the array idea you suggested. It may have to wait until tomorrow, due to the time of evening.
As in every programming language, local variables exist only within the scope of their declaration ( function, trigger or whatever ). They cease to exist outside of that scope. Global variables are global and can be accessed from any piece of code.
like Stragus said, your local variable is essentially destroyed after the trigger ends. If it is running each time a unit dies then your local variable is reset each time to its default at the beginning and will never hold and accurate value. A good rule of thumb is to never set conditions to include local variables.
like my post said on your other thread (that was locked). Local Variables exists only in that one trigger instance. you definitely need a Global Variable. Arrays help with that =P
Going to try it out here shortly! Finishing up with dinner, then I'll give it a run and check it out with a global array.
Double post, apologies.
Thank you all very much for your replies, and helping me to understand how SC2 handles local and global vars. I created a global and used that to check against for the kill rewards. Success!
I've learned a lot from this community. Maybe I'll upload my map once I complete it to try and sort of give back.