Memory Database v7 - nodeGame/nodegame GitHub Wiki

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.

Adding Items to the Memory Database

There are three ways of inserting data in the memory database.

node.done (client-side)

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.

node.set (client-side)

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).

Manual insert (logic-side)

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).

Next

Sources

⚠️ **GitHub.com Fallback** ⚠️