Parameter | Type | Description |
---|---|---|
PLAYER | PLAYER | The next player to switch to. |
Returns nothing. Cannot be used in expressions.
This function changes the current player to the provided player. From the moment that this function is executed, all functions and operations that use the current player will use the one provided until another call to SetPlayer changes it again.
action general a_switchplayer1 named "switch 1";
action general a_switchplayer2 named "switch 2";
action general a_inc named "increment";
action general a_dec named "decrement";
action general a_quit named "quit";
player archetype p_all
{
init()
{
count = 0;
}
onAction(a_inc)
{
textln("Incrementing count...");
count = count + 1;
}
onAction(a_dec)
{
textln("Decrementing count...");
count = count - 1;
}
}
player p_player1 : p_all;
player p_player2 : p_all;
world
{
function printPlayer()
{
if (noCurrentPlayer())
textln("No current player is set.");
else
{
textln("current player is " + identity(player));
textln("player.count is " + player.count);
}
}
onAction(a_switchplayer1)
{
if (currentPlayerIs(p_player1))
textln(identity(p_player1) + " is already current.");
else
setPlayer(p_player1);
}
onAction(a_switchplayer2)
{
if (currentPlayerIs(p_player2))
textln(identity(p_player2) + " is already current.");
else
setPlayer(p_player2);
}
onAction(a_quit)
{
quit;
}
start()
{
textln("Type \"switch 1\" to switch to player 1.");
textln("Type \"switch 2\" to switch to player 2");
textln("Type \"increment\" to increment player.count");
textln("Type \"decrement\" to decrement player.count");
textln("Type \"quit\" to quit.");
printPlayer();
}
afterSuccessfulCommand()
{
printPlayer();
}
}
CurrentPlayerIs() — Tests if the current player is the one provided.
NoCurrentPlayer() — Tests if no current player has been set.