Current Previous Next Step v7 - nodeGame/nodegame GitHub Wiki
- status: complete
- version: 7.x
- follows from: Player IDs
Here is a short primer about the main methods of the Game API to navigate the game sequence.
The GameStage object is a wrapper class containing numeric info about stage, step, and round.
var gameStage = node.game.getCurrentGameStage();
// Example output:
// GameStage {
// stage: 1,
// step: 1,
// round: 1
// }
console.log('This is round: ' + gameStage.round);
// Or the shorthand version:
console.log('This is round: ' + node.game.getRound());
The human-readable id of a step or a stage can be easily obtained:
var stageId = node.game.getStageId(); // Example output: 'instructions'
var stepId = node.game.getStepId(); // Example output: 'instructions_part1'
It is possible to write conditional code based on the id of the stage/step.
if (stageId === 'instructions') {
console.log('You are in the instructions.');
}
if (stepId === 'instructions_part1') {
console.log('You are in the first page of the instructions.');
}
Or more compact:
if (node.game.isStage('instructions')) {
console.log('You are in the instructions.');
}
if (node.game.isStep('instructions_part1')) {
console.log('You are in the first page of the instructions.');
}
if (node.game.isStage(1)) {
console.log('You are in the first stage of the game.');
}
if (node.game.isStep(2)) {
console.log('You are in the second step of the current stage.');
}
if (node.game.isRound(1)) {
console.log('You are in the first round of the current stage.');
}
You can get the GameStage object of a previous step:
var previousStep = node.game.getPreviousStep();
var twoStepsAgo = node.game.getPreviousStep(2);
or the next step:
var nextStep = node.game.getNextStep();
You can force the game to go to any step in the game sequence:
// Go the a stage with id "endgame" (for instance if another player disconnected).
node.game.gotoStep('endgame');
// Go to a step named "step2" within stage "questionnaire".
node.game.gotoStep('questionnaire.step2');
// Equivalent notation, assuming "questionnaire is stage number 4.
node.game.gotoStep('4.2.1');