Can I copy objects? Or how to do multiplayer Forum Home > Construct 2 General > How do I....? |
Post Reply
|
| Author | |
Post Options
Quote Reply
Topic: Can I copy objects? Or how to do multiplayerPosted: 19 Jul 2012 at 12:02am |
|
|
I’ve got a question about copying objects as if they were variables.
I’m making a turn based card game with 4 players (hotseat game). Each player is represented as an Object with a number of attributes (CardsInHand, Score etc.). When Events happen in the game I need to update one of the players attributes depending on whose turn it is. So something like this Player1 Player2 Player3 Player4 <turn 1> CurrentPlayer = Player1 <then play the turn> Add 1 to CurrentPlayer score Add a card to the CurrentPlayer hand Etc. <turn 2> CurrentPlayer = Player2 What’s the best way to accomplish this while keeping the code as simple as possible? |
|
![]() |
|
Post Options
Quote Reply
Posted: 19 Jul 2012 at 12:33am |
|
|
Give the Player object an instance var called 'playerNumber' and set it to 1, 2, 3, 4 on each of your players. Have a global var called 'currentPlayer'. And then you simply do:
Player: playerNumber = currentPlayer Player: Add 1 to score |
|
![]() |
|
Post Options
Quote Reply
Posted: 20 Jul 2012 at 1:04am |
|
|
Ah thanks ramones that looks to work fine.
|
|
![]() |
|
Post Reply
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |