Hello everyone, I am wondering if and how triggers work (perhaps a queue?) when two events are something like "any unit dies" Each different trigger goes to a different player group.
Example: -Trigger 1-
Event: Any unit dies Conditions: Owner of Triggering Unit == 4 ;This is the AI's player number
Actions: If ;works best if I don't put an initial condition for this if
Or
Unit type of triggering unit == Zealot
Unit type of triggering unit == Ghost
Unit type of triggering unit == Firebat
Unit type of triggering unit == Kerrigan - Void
Unit type of triggering unit == Hydralisk
Then: Add 10 minerals for player 5
Add 10 minerals for player 6
Add 10 minerals for player 7
Trigger 2 is similar but instead of the initial condition of player 4, it is 8. In addition 10 minerals are added to player 1, 2, and 3.
My question is, if a unit dies, will the code make a queue such that it checks the first trigger with event "any unit dies" and then the second? Or will it just break completely? I'm curious because both triggers use the same event but different conditions (I would assume this is fine). The other issue is that these two triggers will happen like every 2-5 seconds and I don't want any issues to occur. Edit: The reason I am worried about the time is if it does make a queue, but the frequency is high, there might be some delay to the mineral addition.
I was also skeptical of combining these two triggers into one trigger.
P.S. I would test but I have not figure out how to be on 2 teams at different times :P
Always combine triggers with same event for performance sake. In this case you have also very similar conditions:
Event -> Any Unit Dies
Condition -> OR : Unit type of triggering unit (all your types)
Actions -> switch(Owner of Triggering Unit) Case (4): Do your actions here Case (8): Do your actions here Default: -- Nothing here
This is easy to understand (very important if you need to modify it in the future), good on performance, no queue problems, very clear and easy to extend.
You could also make an array of units type you want to trigger, make a function which makes a check for all of them and put that into conditions. This is somewhat advanced too. Then I would also suggest not using direct numbers for referencing players. Magic numbers are not that good in programming.
Rollback Post to RevisionRollBack
Battle.net wants to call me InsaneMst, Insane... but you should call me InsaneMonster!
How should I reference players, the GUI wants an integer. If you mean this:
Add 10 minerals for player 5
Add 10 minerals for player 6
Add 10 minerals for player 7
I can't think of a better way. They are in a player group called bottom force. But I am unsure if I can do add 10 minerals for each player in x player group. I'm a noob, this is my first map :)
If you have a player group, for each player in the group is a very good solution. This way you can change the group somewhere else without rewriting code here. That's the point of programming actually. Make things work in a way that is fast and easy to change.
In general, if you don't have player groups, I advice to use global variables:
Player01User = 1 Player02AI = 2
etc...
You can also use both, of course. The reason for this is that you understand better what is going on and, above all, you can change a player without rewriting magic numbers all around. Of course the name I gave is just an example :)
Rollback Post to RevisionRollBack
Battle.net wants to call me InsaneMst, Insane... but you should call me InsaneMonster!
Use an array to map a player group to the dying units owner. If the dying unit has no associated player group then ignore it (not an AI player dying). Data tables can be used to resolve if the unit is an appropriate unit type efficiently with O(1) complexity.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hello everyone, I am wondering if and how triggers work (perhaps a queue?) when two events are something like "any unit dies"
Each different trigger goes to a different player group.
Example:
-Trigger 1-
Event: Any unit dies
Conditions: Owner of Triggering Unit == 4 ;This is the AI's player number
Actions: If ;works best if I don't put an initial condition for this if
Or
Unit type of triggering unit == Zealot
Unit type of triggering unit == Ghost
Unit type of triggering unit == Firebat
Unit type of triggering unit == Kerrigan - Void
Unit type of triggering unit == Hydralisk
Then:
Add 10 minerals for player 5
Add 10 minerals for player 6
Add 10 minerals for player 7
Trigger 2 is similar but instead of the initial condition of player 4, it is 8. In addition 10 minerals are added to player 1, 2, and 3.
My question is, if a unit dies, will the code make a queue such that it checks the first trigger with event "any unit dies" and then the second?
Or will it just break completely? I'm curious because both triggers use the same event but different conditions (I would assume this is fine). The other issue is that these two triggers will happen like every 2-5 seconds and I don't want any issues to occur.
Edit: The reason I am worried about the time is if it does make a queue, but the frequency is high, there might be some delay to the mineral addition.
I was also skeptical of combining these two triggers into one trigger.
P.S. I would test but I have not figure out how to be on 2 teams at different times :P
Always combine triggers with same event for performance sake. In this case you have also very similar conditions:
Event -> Any Unit Dies
Condition -> OR : Unit type of triggering unit (all your types)
Actions ->
switch(Owner of Triggering Unit)
Case (4):
Do your actions here
Case (8):
Do your actions here
Default:
-- Nothing here
This is easy to understand (very important if you need to modify it in the future), good on performance, no queue problems, very clear and easy to extend.
You could also make an array of units type you want to trigger, make a function which makes a check for all of them and put that into conditions. This is somewhat advanced too. Then I would also suggest not using direct numbers for referencing players. Magic numbers are not that good in programming.
Battle.net wants to call me InsaneMst, Insane... but you should call me InsaneMonster!
Author of InsaneAI library, InsaneCredits library, InsaneDebug library, InsaneTransmission library, InsaneUI library and InsaneBriefing library.
Author of Mercenary Business - Top 10 Rock The Cabinet 2017: Co-op edition.
That seems a lot simpler xD
How should I reference players, the GUI wants an integer.
If you mean this:
Add 10 minerals for player 5
Add 10 minerals for player 6
Add 10 minerals for player 7
I can't think of a better way. They are in a player group called bottom force. But I am unsure if I can do add 10 minerals for each player in x player group. I'm a noob, this is my first map :)
If you have a player group, for each player in the group is a very good solution. This way you can change the group somewhere else without rewriting code here. That's the point of programming actually. Make things work in a way that is fast and easy to change.
In general, if you don't have player groups, I advice to use global variables:
Player01User = 1
Player02AI = 2
etc...
You can also use both, of course. The reason for this is that you understand better what is going on and, above all, you can change a player without rewriting magic numbers all around. Of course the name I gave is just an example :)
Battle.net wants to call me InsaneMst, Insane... but you should call me InsaneMonster!
Author of InsaneAI library, InsaneCredits library, InsaneDebug library, InsaneTransmission library, InsaneUI library and InsaneBriefing library.
Author of Mercenary Business - Top 10 Rock The Cabinet 2017: Co-op edition.
Use an array to map a player group to the dying units owner. If the dying unit has no associated player group then ignore it (not an AI player dying). Data tables can be used to resolve if the unit is an appropriate unit type efficiently with O(1) complexity.