-
Notifications
You must be signed in to change notification settings - Fork 18
Current Previous Next Step v7
- 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');
Go back to the wiki Home.
Copyright (C) 2021 Stefano Balietti
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.