Can I copy objects? Or how to do multiplayer

Forum Home Forum Home > Construct 2 General > How do I....?
 Post Reply Post Reply
Author
839 Rep
Post Options Post Options   Quote Dru Quote  Post ReplyReply Direct Link To This Post Topic: Can I copy objects? Or how to do multiplayer
    Posted: 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?
Back to Top
9,252 Rep
Post Options Post Options   Quote ramones Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
839 Rep
Post Options Post Options   Quote Dru Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jul 2012 at 1:04am
Ah thanks ramones that looks to work fine.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down