| Reference | Downloads | Github

Pavlovia + phaser3: tips for writing data?


I’ve previously hosted experiments on Pavlovia written using the jsPsych library, which has worked very nicely.

My next task is written in js/html using phaser 3 ( At the current stage of testing, participant responses are being written client-side into a JSON structure.

Is there an easy way to ensure that this data can be written to the Pavlovia server? One option I’m thinking of is just using the jsPsych data write function ({key: value, …}); ), but it seems like there might be a more straightforward way to do this that doesn’t require importing additional libraries?

Any tips would be much appreciated.



NB I haven’t uploaded the task repository to Pavlovia yet as I wanted to try and work out where best to host this study first, but am happy to do so if this would be helpful to answer the question or be useful for other users

Hey @agnesnorbury, what an interesting question, apologies for the late reply. If you are happy using PsychoJS, would be the way to go I believe. Should you be willing to share if only a short sample of what your experiment looks like, I might be able to provide you with more details. Here to help, thanks, s.

Thanks so much for getting back to me @sotiri , I’m sure it’s a busy time in the world of online studies…

I uploaded a test version of the game code at (see for a demo).

All the game functionality seems to work when I run it from the Pavlovia dashboard in pilot mode. I can also see the trial data logging in the console (as set up for debugging purposes), which is great.

Currently, trial data generated in the different game scenes is being stored in the global phaser data registry using this.registry.set() (see e.g. js/scenes/platformerSceneA.js, line 384).

Should it then be as straightforward as loading the psychoJS library in index.html, importing it into the relevant scene modules (e.g. js/scenes/platformerSceneA.js), and calling something like on each update?
I have not actually used PsychoJS to code experiments before so am not sure if it’s possible to just cherry pick it’s functions like this, without using the PsychoJS experiment structure.

I’ll have a go at implementing the above workaround this afternoon, and update this post if successful in case it’s useful to anyone else.



OK this is one super cool experiment you have in the works! What you propose makes a lot of sense, please allow me some time to run a few tests, I should be able to have a definite answer for you fairly soon. Happy coding! s.

Hey Agnes, how is your project coming along? As it happens getting the data to save on demand like you describe requires first adding script tags for a few of the runtime dependencies for PsychoJS, like you do with phaser in your index.html, then importing the library in your code and calling the appropriate methods. You can see how in this fork -note the IIFE for initialising the psychoJS controller inside the platformerSceneA module because it’s an asynchronous call :blush:

You can test that below with data up to the second trial saved when you close the browser tab:

I suspect your use case is slightly more involved, but I’m hoping that should help get you started for now. On standby in case you need more details, x

Thanks so much for taking the time to do this, this is incredibly helpful! I’ll have a go at implementing this method (hopefully this week) and will let you know then if everything seems to be working OK.