Can I copy objects? Or how to do multiplayer

Get help using Construct 2

Post » Thu Jul 19, 2012 12:02 am

Ive got a question about copying objects as if they were variables.

Im 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


Whats the best way to accomplish this while keeping the code as simple as possible?
B
7
S
2
G
1
Posts: 7
Reputation: 1,581

Post » Thu Jul 19, 2012 12:33 am

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
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,000

Post » Fri Jul 20, 2012 1:04 am

Ah thanks ramones that looks to work fine.
B
7
S
2
G
1
Posts: 7
Reputation: 1,581


Return to How do I....?

Who is online

Users browsing this forum: R0J0hound, randomly, spcsmrf, Zakeru and 18 guests