The “take a break” message appears on every trial. And I found trials.thisTrialN says 0 all the time.
My question is how to get the current trial number in Javascript? Or, one step further, how can I do break within the experimental loop with the online experiment.
I read several topics related to this question but did not find a proper solution therefore I ask the question here again.
Right! || shouldn’t be the issue. I found this issue is due to trials.thisTrialN doesn’t get the correct trail numbers. Interestingly aleart(trials.thisIndex seems to say the correct index number but not thisTrailN.
I ran into the same issue and I tried it using both thisN and thisTrialN as the attributes.
thisTrialN prints 0 and thisN reports the total number of trials in the condition file. The numbers are reported correctly when tested locally using Python code.
Weirdly enough when I started a brand new experiment the trial number was reported correctly but not on my main experiment.
I had to add a variable which incremented at the end of the routine to fix this. However, this shouldn’t be “solution” so I actually also want to know the reason for this issue.
Hi @wakecarter
Thanks for your reply. In Javascript, alert(trials.thisN) gives me the total number of trials in the current loop. However, locally, in python both trials.thisN nad trials.thisTrialN showed the current trial number.
Hi @Tamer_Gezici,
Did you define the trail number as a global variable? If I define a trail number at Begin Experiments, javascript could not find the variable when increment because the variable is defined under the function function experimentInit(). Could you share this part of your code? Many thanks.
That should be correct unless you have misspelled the variable. I say that since you spelled it as “myTrail” instead of “myTrial”.
If that is not the case, clear browser cache and try again. If you use chrome do SHIFT+CTRL+J in the experiment page and click the “Sources tab” there you will see a .js file with the same name as your experiment. Right click it and open it in a new tab and search if you have the latest version online via CTRL+F’ing your variable in the page.
Thanks. I got a typo, but the variable names are constant in the code. I checked the .js file and it is the latest version. Unfortunately, still doesn’t work on my side.
That is a good idea but it may cause bugs. I am new to Psychopy so take my words with a grain of salt though.
You asked me for code earlier however I dont have that experiment anymore (I deleted it and started from scratch) here is an example experiment which you can take a look at its code. It shouldnt make a difference between using var_trial ++; and what I did but since I noticed the python code wasnt converted this way I did it using this way. See if doing it like this works. The variable I used is var_trial.
@Miao I ran into similar errors and seems like I read many of the same threads you did. I decided to create my own counters and couldn’t get it to work until I copied the code into the “Each Frame” tab. I wrote in python in Builder and let PsychoPy produce the JS code and then I substituted my own counter variable. This is the setup I am using in my experiment for my break screen:
Begin Experiment:
exp_target_loop = 0;
Begin Routine:
if ((exp_target_loop !== 31)) {
continueRoutine = false;
}
Each Frame:
if ((exp_target_loop !== 31)) {
continueRoutine = false;
}