Skip to content
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

Resource/Logic shared dynamically between games #156

Open
JamesPHoughton opened this issue Aug 28, 2020 · 1 comment
Open

Resource/Logic shared dynamically between games #156

JamesPHoughton opened this issue Aug 28, 2020 · 1 comment

Comments

@JamesPHoughton
Copy link
Contributor

I'd like to assign manipulations to players in one game based upon the results of players' decisions in another game, possibly in which the games are happening simultaneously. (Essentially because I'm abusing Empirica as a survey platform and I want to do adaptive surveys, but I can see the use case extending to actual multiparty games).

In order to do so, I either want to have some code that runs at the server level that can decide top-down which manipulations to give, or a way of sharing information between games (even just writing to a file on the server, or a new table in the DB). @npaton, is there something of that nature already built into Empirica, or a place where I could insert a lever to stick one in?

Thanks!
James

@JamesPHoughton JamesPHoughton changed the title Resource/Logic shared between games Resource/Logic shared dynamically between games Aug 28, 2020
@npaton
Copy link
Contributor

npaton commented Sep 7, 2020

Hey James. Sorry took me a while to answer! Yeah, no, there's nothing Empirica specific right now. 🤷

The good news is that it should be pretty easy to store stuff in the DB. You can just create and use a new table like this (from the example found here):

// When you create a collection on the server:
Todos = new Mongo.Collection('todos');
// You are creating a collection within MongoDB, and an interface to that
// collection to be used on the server. It’s a fairly straightforward layer on
// top of the underlying Node MongoDB driver, but with a synchronous API:
// This line won't complete until the insert is done
Todos.insert({ _id: 'my-todo', stuff: "things" });
// So this line will return something
const todo = Todos.findOne({_id: 'my-todo'});
// Look ma, no callbacks!
console.log(todo);

That will work easily on the server-side. Just declare the Mongo.Collection outside any callbacks, and pass the name of the table in the DB, and you should be good.

There are a couple caveats:

  • This will not be exported by the Empirica export function in the admin UI
  • Concurrency can be a problem: if you're trying to write and read from this table at the same time from 2 games, you might have some data corruption, depending on what you're trying to do.

Then, if you need a new collection on the client side, in the browser, that will be a bit more work. Let me know and I can try to help you get that going.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants