psychopy.org | Reference | Downloads | Github

Javascript variables won't persist

OS: Ubuntu Linux, v16.04
PsychoPy: 3.1.4
javascript variables won’t persist

URL of experiment: https://run.pavlovia.org/RobinScaife/openiat/html/

Description of the problem:

This is to make an Implicit Association Test (which we previously had working in old PsychoPy) work online with Pavlovia. I can’t seem to refer to js variables defined in an initial block from a subsequent block

In SetupCode block I have JS code (under ‘begin experiment’):

`trainlabelsL=['A = \nWhite','A = \nBlack'];`

later (after some instructions and a short practice), I have the main experiment, controlled by ‘superloop’ and which begins with a block Superloop_code which is intended to declare the variables for each loop based on the loop count. Under ‘begin routine’ I have this JS

`trainlabelL=trainlabelsL[superloop.thisRepN];`

Later on, in the block Training2, $trainlabelL is used in a text display block.

However, there are two issues with making this work

  1. The array trainlabelsL is not recognised. Although I tried to define it in SetupCode, by the time we get to Superloop_code it seems to have been forgotten (or I am calling it wrong)

  2. The way I index the number of reptitions (superloop.thisRepN) doesn’t work - I assume psychopy isn’t creating this variable for the loop count. So which variable name should I use?

In Superloop_code I ‘hard code’ the variables’ and make everything run, so I’m pretty sure it is just my variables and their indexing I have an issue with

`trainlabelL=['A = \nWhite','A = \nBlack'][0]`

If you run the only experiment you will see, when you get to the training block, that the top left label is missing, while the top right label is there (but only because I hard coded its value)

Hi @tomstafford, yes currently the trial handler attributes are not ready for use, as they are not updating in realtime. What you need to do instead is manually code your own trial and block counters. Take a look at this post for an example.

@tomstafford, perhaps we can have a look at working together on your task so that you do not require much use of code components, and rather rely more on information stored in the conditions files.

Does this mean that we will not be able to access data via the trial handler? I’m also working on an IAT, and I’m at the stage where I need to calculate a d score in order to provide feedback.

Ideally I’d write a brief algorithm to calculate said score, but I’m struggling with accessing previous RTs un my last block

I’d be up for that! What is the first step?

ps I think @jon was thinking looking into converting the IAT expt to online at one point

Yes, we would like to have a version of the IAT as a demo although we would use different stimuli etc, so this would be mutually beneficial. If you would be able to msg me with details of your method, I will start looking at how you can get your task running online.

@Laur_R, you are still able to access your data, if you start a new thread with your requirements, I can show you some ways of getting the data your want using code components.