I understand the difference between global and private. These are different scopes for the variables designating how they can be accessed.
My question is... how do you get a variable specific to a player? Do you have to set a ton of variables like "Player 1 Health", "Player 2 Health", etc.. or can you flag the variables as being client variables.. so each player gets a "copy" of the same variable?
And likewise.. triggers. If a trigger is on, it is on for all players, correct?
Triggers and variables are always accessible for all players. It needs to be like this, otherwise the clients could desynchronize and the game would break.
To enable triggers for certain players you should use conditions. You can have a trigger run only when player X triggered it.
For variables you should use arrays. Every array variable has different slot in which you can put information. You can use one slot for each player. This way you only need to declare one PlayerHealth variable which is able to store every player's health.
player Indicies are simply an int, so you can map to a player's info using a simple indicie, so if I understand your question correctly, the answer is... all you need to keep track of is something like (int playerIndex;) and then you can as you've said get PlayerHealth of [playerIndex]
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
I understand the difference between global and private. These are different scopes for the variables designating how they can be accessed.
My question is... how do you get a variable specific to a player? Do you have to set a ton of variables like "Player 1 Health", "Player 2 Health", etc.. or can you flag the variables as being client variables.. so each player gets a "copy" of the same variable?
And likewise.. triggers. If a trigger is on, it is on for all players, correct?
Variables are either, global, thread local or local.
Use arrays, player is just an index so it maps perfectly. And yes all code is synchronised for all players.
Triggers and variables are always accessible for all players. It needs to be like this, otherwise the clients could desynchronize and the game would break.
To enable triggers for certain players you should use conditions. You can have a trigger run only when player X triggered it.
For variables you should use arrays. Every array variable has different slot in which you can put information. You can use one slot for each player. This way you only need to declare one PlayerHealth variable which is able to store every player's health.
@s3rius: Go
Right, so I would reference it by saying "PlayerHealth[TriggeringPlayer]". That makes sense.
@JTG2003: Go
player Indicies are simply an int, so you can map to a player's info using a simple indicie, so if I understand your question correctly, the answer is... all you need to keep track of is something like (int playerIndex;) and then you can as you've said get PlayerHealth of [playerIndex]