-
Notifications
You must be signed in to change notification settings - Fork 18
Default Step Properties v7
- status: complete
- version: 7.x
- follows from: Client Types
Game developers can define their step properties (as many as needed), but some names are reserved by nodeGame. The most important reserved properties are:
-
frame
: string|object
An HTML resource to load in the frame (browser-only). By default, all steps within the same stage re-use the same frame loaded at step 1 of the stage, unless otherwise speecified. the frame is reloaded only between stages, or consecutive rounds. For specific options, see theloadFrame
method of the Window API. -
init
: function
Defines an initialization function executed before each stage / step. Listeners registered here are available throughout the stage / step. -
exit
: function
Defines an exit function executed before after the stage / step was completed, and before the next one begins. Listeners registered here are deleted immediately. -
timer
: number|object
Configures the internal timer and Visual Timers objects, if any. If the parameter is a number, it specifies the duration of the timer in milliseconds. If object, it allows full configuration of the timer. For details, see Visual Timer. -
stepRule
: function|string
Defines the condition for the client to enter into the next step / stage. If the function returnsTRUE
, the next stage in the game-sequence will be executed.
The done callback receives the same input parameters of node.done
and can modify them or completely halt the procedure to terminate the current step if some conditions are not satisfied.
stager.extendStep('instructions', {
cb: function() {
// In this example, we just call node.done after 2 seconds.
setTimeout(function() {
// The value passed to node.done is evaluated by the done callback.
node.done({ foo: 'bar' });
}, 2000);
},
// The done callback evaluates if conditions for terminating the
// current step are satisfied and/or modifies done parameters.
done: function(results) {
// results is equal to { foo: 'bar'}.
// If some conditions are not satisfied, the done callback can
// block the execution by returning false.
if (results.foo !== 'bar') return false;
// The done callback can also modify the results that will sent
// to the server.
results.foo = 'bar2';
return results;
// Notice: for retro-compatibility returning true is ignored and
// not sent to the server. If you need to send a truthy value,
// consider sending 1, or [true].
}
});
It is possible to execute callbacks just before and after a certain
step is executed. Just add the init
and exit
properties to the
step object. For example:
stager.extendStep('instructions', {
init: function() {
// See the next section of the tutorial
// to know more about the `node.on` command.
node.on('myEvent', function() {
console.log('I am valid only during this step');
});
console.log('I am executed before the step callback');
},
exit: function() {
console.log('I come after the step is done, before a new ones begins.');
}
});
Likewise, it is possible to add init
and exit
callbacks to the
stage object as well.
// Notice extend**Stage**.
stager.extendStage('game', {
init: function() {
node.on('myEventInGame', function() {
console.log('I am valid through all the steps and all the ' +
'rounds of the stage game.');
});
console.log('I am executed before any step in the game stage.');
},
exit: function() {
console.log('I come after the stage is done, before a new one begins.');
}
});
Important! The init
and exit
properties behave differently from other properties: they are not inherited by each step inside the stage. This means that, for instance, the init
property of the stage is executed only once at the beginning of the stage, regardless of how many rounds and steps the stage has got.
-
minPlayers
: array [number, function]
Defines the minimum number of players that need to be connected simultaneously in order to continue the game. As soon as the requirement is not met the callback function is invoked. -
maxPlayes
: array [number, function]
Defines the maximum number of players that need to be connected simultaneously in order to continue the game. As soon as the requirement is not met the callback function is invoked. -
exactPlayers
: array [number, function]
Defines an exact number of players that need to be connected simultaneously in order to continue the game. As soon as the requirement is not met the callback function is invoked. -
globals
: object
Defines properties that will be available at run-time undernode.game.globals
.
- The full Stager API
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.