Memory Database v7 - nodeGame/nodegame GitHub Wiki
- status: complete
- version: 7.x
- follows from: Current, Previous, Next Step
The memory database is available under node.game.memory
of
the logic client type.
The memory database is an instance of the NDDB database and inherits all its methods.
There are three ways of inserting data in the memory database.
The input parameters to node.done
, which terminates the step, are automatically added to the database.
// Stage 1.1.1.
// Client id=A.
node.done({ foo: "bar"});
// Client id=B.
node.done({ foo: "bar"});
// Logic.
memory.size(); // 2 -> 1 item from A, 1 item from B.
Clients can insert new items in the memory database, without terminating the step, using the command node.set
. This is useful for continuous-time games.
// Client id=A (stage: 2.1.1).
node.set({ value: 1 });
node.set({ value: 2 });
// Logic.
memory.size(); // 4 (2 items from previous example, and 2 new ones).
The logic can manually add items to the database. Each item must contain a player
and stage
property, or an error will be raised. This is useful to fill in values from disconnected players.
// Logic.
memory.add({
player: 'B',
stage: { stage: 2, step: 1, round: 1},
value: 3
});
memory.size(); // 5 (4 items from previous examples, and 1 new one).