Hi,
So I’m making a TCG game similar to Magic: the Gathering or Hearthstone. I have a custom player state, game state, and player controller class. I’m pulling out my hair trying to figure out how to randomize which player goes first, and to allow the player whos turn it is, to advance the game and end their turn. I’ve ended up with some kind of race condition or something.
In my GameState, I have an array containing the “Player Order.” Index 0 represents the first player to go, index 1 represents the 2nd player to go. The int within the array represents the player’s ID (taken from gamestate itself). It uses the “get player state from index” function to search the general player array class and find matching ID’s.
In my player controller, I have some client side checks to see if the “active player ID” is the same as the game states. If it is, then I can call a server function to move the game forward a phase (main phase → combat → end turn for example).
However, sometimes the player controller function fails, and I have mismatched values. I have been printing the values to the screen every time it fails, I often get this result:
On one instance of the client:
Active Player ID:552 (the one we need to progress the game) red text
Current Player ID: 553 (the player controllers) green text
On the other instance of the client:
Active Player ID:553 (the one we need to progress the game) red text
Current Player ID: 552 (the player controllers) green text
Both of these clients cannot progress the game, because the “active player” is not equal to the player attempting to call the function. But the ID’s for both of them are correct on the OTHER client’s information…
Other times it works perfectly as if there was no problem at all. Note that I am testing this using PIE, on a dedicated server with 2 players. And from these, I assumed that my logic for progressing the game was correct.
This is super frustrating as I cannot consistently reproduce this error. It seems like some kind of race condition (or else I don’t fully grasp replication).
Would really appreciate any help on this issue! Thanks.