So i'm reconfiguring all my triggers in my map to be array based, each index in the array being a different player and just having some core triggers that work for all players.
My question is how can i stop specific triggers if a key in unpressed by a specific player. Lets say i have a move forward trigger and it activates when any player presses W down, then i use the player # of the player who presses W down as the index to use the correct unit forawrd constantly. Now that player unpresses W. How would i stop the specific looping movement trigger for that specific player? Hope that made sense.
Edit: this probably wasn't the best example as i could have a condition, "W pressed down" in this instance, but there are other triggers i have that aren't as conveniently fixed.
Trigger Array, One looping movement trigger for each player in game.
2 Integer Arrays for Vertical and Horizonal Movement.
The integer arrays should be flagged ±1 for pressed, 0 for unpressed.
If W is pressed, Vertical += 1, if S is pressed, Vert -=1. Vice versa for unpressed.
This way if both Up/Down are pressed, it will equate zero and the condition below this one will be false.Same case with Left/Right
Take the sum of the key integers
Vert[playerNum] + Horz[playerNum]
If it's NOT 0, it means there is a key pressed. [<= The Condition]
On the vertical axis, 1 would mean forward movement, -1 would mean backwards. Same case for horizontal, left or right, you decide.
As long as the sum of all the key integers is NOT 0, it means there is a key pressed and movement should occur, so enable the corresponding movement loop trigger for that player.
In the movement trigger, Simply calculate movement based off the Vertical and Horizontal States.
For a more general case, like Fuzzy said, have two triggers. The first fires when a certain event comes to pass and its only action is to set the value of an index in an array (which matches the triggering player) to "1".
Then have a second trigger which periodically (or when triggered by a second event) cycles through the list of players (i.e. picked integer 1 to 4 for four players) and "if array [picked integer] = 1 is true" then execute an action, otherwise it checks the next player in the cycle.
That would work too, though there would be some redundancy when it comes to checking conditions.
It's more efficient process wise to have one move loop trigger declared for each player.
That way, if a player is not moving, their move trigger can be disabled and its less taxing on the processor.
With a single universal move trigger, it should be possible to have Periodic Events that are independent of each other.
Say I have trigger T.
I have 2 Periodic events attached to it, One for each player.
The first Periodic event would exclusively move only player 1, no conditions required.
The second would exclusively move only player 2. Though I'm not too sure what the best way to trigger this is.. Its debatable.
Thanks guys, the idea of a trigger array could be just what i needed, i can try to "stop all instances" of a specific slot in the array and that just may do it :D, thanks!
So i'm reconfiguring all my triggers in my map to be array based, each index in the array being a different player and just having some core triggers that work for all players.
My question is how can i stop specific triggers if a key in unpressed by a specific player. Lets say i have a move forward trigger and it activates when any player presses W down, then i use the player # of the player who presses W down as the index to use the correct unit forawrd constantly. Now that player unpresses W. How would i stop the specific looping movement trigger for that specific player? Hope that made sense.
Edit: this probably wasn't the best example as i could have a condition, "W pressed down" in this instance, but there are other triggers i have that aren't as conveniently fixed.
You will need:
The integer arrays should be flagged ±1 for pressed, 0 for unpressed.
If W is pressed, Vertical += 1, if S is pressed, Vert -=1. Vice versa for unpressed.
This way if both Up/Down are pressed, it will equate zero and the condition below this one will be false.Same case with Left/Right
Take the sum of the key integers
Vert[playerNum] + Horz[playerNum]
If it's NOT 0, it means there is a key pressed. [<= The Condition]
On the vertical axis, 1 would mean forward movement, -1 would mean backwards. Same case for horizontal, left or right, you decide.
As long as the sum of all the key integers is NOT 0, it means there is a key pressed and movement should occur, so enable the corresponding movement loop trigger for that player.
In the movement trigger, Simply calculate movement based off the Vertical and Horizontal States.
I hope that made sense. :)
For a more general case, like Fuzzy said, have two triggers. The first fires when a certain event comes to pass and its only action is to set the value of an index in an array (which matches the triggering player) to "1".
Then have a second trigger which periodically (or when triggered by a second event) cycles through the list of players (i.e. picked integer 1 to 4 for four players) and "if array [picked integer] = 1 is true" then execute an action, otherwise it checks the next player in the cycle.
Is that whatcha after?
@ChromiumBoy: Go
That would work too, though there would be some redundancy when it comes to checking conditions.
It's more efficient process wise to have one move loop trigger declared for each player.
That way, if a player is not moving, their move trigger can be disabled and its less taxing on the processor.
With a single universal move trigger, it should be possible to have Periodic Events that are independent of each other.
Say I have trigger T.
I have 2 Periodic events attached to it, One for each player. The first Periodic event would exclusively move only player 1, no conditions required. The second would exclusively move only player 2. Though I'm not too sure what the best way to trigger this is.. Its debatable.
Thanks guys, the idea of a trigger array could be just what i needed, i can try to "stop all instances" of a specific slot in the array and that just may do it :D, thanks!
@crazyfingers619: Go
Theres a function to disable/enable specific triggers. You could use that to pause the movement triggers when they are not needed.