- Joined
- Sep 5, 2019
- Messages
- 33
I am trying to have creeps regularly respawn (every minute), if the hero has defeated that group. The first group spawns in the first region, and after that nothing happens. What am i doing wrong? Thanks!
I have their size set to thirty, although there is no initial value (empty group). At the moment I am not using all thirty, although I plan to. Do they all need to be filled for it to work?Unit Group and Player Group arrays need to have their Size initialized. So open the Variable Editor and set the Size of your Unit Group to however many of these there will be.
That being said, your triggers looks a bit weird. What are you trying to achieve exactly?
I feel like it'd be easier to just catch when a creep dies, remove it from the unit group that it belongs to, subtract from an integer counter that keeps track of the total units in the unit group (more efficient than re-counting the total number of units in said group each time), and if that integer is equal to 0 you know that the group is empty and you can respawn the creeps.
Also, be careful with using For Loops that all share the same Integer variable. IntegerA is a global variable and each of your nested Loops (loop within a loop) is using it, thus changing it's value for ALL of them.
Will do! Thank you for all the help (=Regarding the Unit Group:
The Size that you set is the limit to how many Unit Groups you can create. I would always keep the Size at the exact amount that you need (if possible) as this is more efficient.
Regarding For Loops:
The variable is an Integer that represents the current iteration of the loop. So if you loop from 1 to 5 using Integer A:
First cycle, Integer A = 1, the actions run...
Next cycle, Integer A = 2, the actions run...
Next cycle, Integer A = 3, the actions run...
Next cycle, Integer A = 4, the actions run...
Final cycle, Integer A = 5, the actions run...
So Integer A can be referenced if you wanted to take advantage of that number. For example, let's say your map has 5 players in it, and you wanted to create a Hero for each of them and track that Hero using a Unit array:
Here we're using Integer A to represent the Player in our Create unit function (using convert player index) and the Player Number in the [index] of our unit array, PlayerHero[].
For each (Integer A) from 1 to 5 do (Actions)
Unit - Create 1 Paladin for Player(Integer A) at some point...
Set Variable PlayerHero[Integer A] = Last created unit
Use case aside, the general rule of thumb is to create new Integer variables for your For Loops and use those instead of Integer A/B, this way you avoid overwriting their values and can nest as many loops as you'd like. To do this look for the For Loop action that lets you choose an Integer variable of your liking.
Regarding your respawn system:
Another benefit of doing it the way I described is that the time before the creeps respawn would always be the same.
Kill last creep -> Wait 60.00 seconds -> Respawn creeps.
With your design, there's a chance that you kill the last creep a second before the Periodic Interval occurs, causing the creeps to respawn almost immediately.
Hey! Sorry one more question, you said "catch when a creep dies, remove it from the unit group that it belongs to", what's an easy way to do that? The trigger I'm using right now feels ridiculously overcomplicated, not to mention inefficient.Regarding the Unit Group:
The Size that you set is the limit to how many Unit Groups you can create. I would always keep the Size at the exact amount that you need (if possible) as this is more efficient.
Regarding For Loops:
The variable in the loop is an Integer that represents the current iteration of the loop. So if you loop from 1 to 5 using Integer A:
First cycle, Integer A = 1, the actions run...
Next cycle, Integer A = 2, the actions run...
Next cycle, Integer A = 3, the actions run...
Next cycle, Integer A = 4, the actions run...
Final cycle, Integer A = 5, the actions run...
Integer A provides us with a way to reference the current iteration of the loop, which can be very useful.
For example, let's say your map has 5 players in it, and you wanted to create a Hero for each of them and track that Hero using a Unit array:
Here we're using Integer A to represent the Player in our Create unit function (using convert player index) and the Player Number in the [index] of our unit array, PlayerHero[].
For each (Integer A) from 1 to 5 do (Actions)
Unit - Create 1 Paladin for Player(Integer A) at some point...
Set Variable PlayerHero[Integer A] = Last created unit
Use cases aside, the general rule of thumb is to create new Integer variables for your For Loops and use those instead of Integer A/B, this way you avoid overwriting their values and can nest as many loops as you'd like. To do this look for the For Loop action that lets you choose an Integer variable instead of having to use A/B.
Regarding your respawn system:
Another benefit of doing it the way I described is that the time before the creeps respawn would be constant.
Kill last creep -> Wait 60.00 seconds -> Respawn creeps.
With your design, there's a chance that you kill the last creep a second before the Periodic Interval occurs, causing the creeps to respawn almost immediately.