-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing or outdated docs for client-side API objects (e.g. undefined currentRound, currentGame etc.) #10
Comments
I can also confirm that server-side models seem to comply with the docs ( Empirica.onStageStart(({ stage }) => {
const game = stage.currentGame;
game.players.forEach((player, i) => {
const position = {
x: game.gameConfig.startPosition,
y: game.gameConfig.startPosition,
}
player.set('position', position, { ephemeral: true });
});
}); And as an offtopic, which I'm currently struggling with: could you suggest the best way to record history of player positions within the current architecture? I can imagine two scenarios: 1) recording player position history on the server (I don't know if |
Thank you for ticket, I will try to fix the docs asap. For the position, I assume this is mouse positions? That might be a lot of data, so it would be preferable to store it separately from the main data. With ephemeral, the Untested example: const fs = require("fs");
const path = require("path");
// The file path where we'll store the player data
const filePath = path.join(__dirname, "playerData.json");
// Ideally, we'd close the stream when we're done writing, but, normally, Node.js
// will close it when the process exits.
const stream = fs.createWriteStream(filePath, { flags: "a" });
function appendPlayerData(data) {
data.timestamp = new Date().toISOString();
const dataString = JSON.stringify(data) + "\n";
stream.write(dataString, (err) => {
if (err) {
console.error("Failed to append data:", err);
}
});
}
appendPlayerData({ playerID: "player123", x: 100, y: 200 });
appendPlayerData({ playerID: "player456", x: 150, y: 250 }); |
Thank you for your quick answer. Also, I count myself luck, doing this experiment just weeks after you added Maybe this question could be a separate issue after all -- I did think of adding some kind of "question" issue but currently only bug / feature can be submitted in Empirica code repo. I guess users considering highly real-time experiments could be able to find it (BTW I know about a similar experiment implemented in Empirica 1, and actually it was implemented using Meteor's DDP stream for communication between the clients, who submitted the position history on stage end; it'll be interesting to see how it will compare to using Empirica 2 ephemeral player updates). |
https://docs.empirica.ly/overview/api
I tried to use objects returned by Empirica React hooks along the lines of the documentation for Server:
https://docs.empirica.ly/overview/api#server-objects
It looks like only some objects included in the docs are defined, in particular all "currentX" properties are not set, unlike their "X" versions.
Is it that all API is in fact different than in the docs, or is the client-side API different from Server?
If I learn something new about your object API, I'd be happy to contribute to the docs, but at this point I'm confused what is wrong: the behaviour or the docs.
All game-related objects were added in
Empirica.onGameStart
with calls such asHere's a test component:
Firefox console output at localhost:3000:

The text was updated successfully, but these errors were encountered: