Code Component not working when running in Pavlovia

Hmm…You were supposed to get sth like this (the trial number +1):
image
Could you please post screenshots of your imagetrials excel or csv condition file and your imageconditions excel or csv file?
Another possible fix that worked for me when I had a similar issue (I am saying similar because i didn’t have two loops, trials+conditions, but just one, a trial loop) is to:
1.Make your own custom varibales which you create in the begin experiment tab:

my_condition=0;

2.You increment them by one in begin routine tab:

my_condition+=1;

3.Then you use the code I mentioned on my previous post but this time referring to your own variable:

if (my_condition!==67 &&.....){
continueRoutine=false;
}

This is how I managed to solve it and this is how i run my experiment at the moment.

But please do post your excel or csv files, so to rule out the possibility of sth not working as expected because of them.

What is sth? I had never used psychopy before so apologies if i seem clueless. what does sth mean? My conditions file is huge, what exactly did you need to see on it? It is CSV, it contains the names of other CSV files that are selected at random, that then contain image 1, and image 2 (stimuli and stimuli 2) that are shown in the experiment. that is one loop, then it does it again. The Conditions file contains the CSV file names, the onset times for each image the end time for each image, onset time for mask and fixation cross and end time for these too.

Conditions file header row screen shot, and screen shot of one of the headers in the CSV files listed in the first column of the conditions file.

Screenshot 2020-04-22 at 10.48.49

@Jonathan asked you to console.log(ImageConditions.thisN); and from what you posted you were getting only 272, 272, 272… So it seems like no increment was taking place. What is this 272? Do you have 272 conditions (which means rows if we speak for a csv file) in your ImageConditions file? If yes, then it does not increment as it should through your various conditions.

yes there are 272 rows in the conditions file. it is meant to select randomly each time 272 times, the image sets it brings up when testing the study are indeed random and when i run through it all there are all 272 lines used randomly.

Didn’t see the further replies initially. As @phoenix says, the numbers in purple are the console.log output. So, ImageConditions.thisN is just reporting the total number of trials. Change the console.log to tell you ImageConditions.thisTrialN or trials.thisTrialN and see if they increment appropriately.

i have tried replacing ImageConditions.thisN with ImageConditions.thisTrialN and with trials.thisTrialN and i get 0 now where it was 272 previously

Sorry, didn’t read the comment all the way. trials.thisTrialN failing to update is weird, that one should be reliable.

At this point it might be worth creating your own variable to keep track of trial number, as annoying as that is. In beginExperiment, you would put:

trialCounter = 0;

And in begin routine (yes, even in the JS), you would put:

trialCounter = trialCounter + 1;

Try basing the conditional on the value of trialCounter, and logging the value of trialCounter as well.

1 Like

so instead of ImageConditions.trialN or variables use

‘’’
console.log(trialCounter);
if (trialCounter != 3){
continueRoutine=false;
}

‘’’

Yes, exactly. We’re just creating a parallel counter structure.

brilliant. So attached are the changes to the code component made, and the console.

i got the pause as needed after 3 trials! Amazing.

so this indicates that there was something wrong with how i wrote the code originally? So now all i need to do is add in the 2 other additional pause instances to the now existing code…? (3 , 6 , 9 would be the 3 pauses i actually want if testing works…

‘’’
console.log(trialCounter);
if (trialCounter!= 3 && trialCounter != 6 && trialCounter != 9){
continueRoutine=false;
}

‘’’

1 Like

More something weird about the behavior of [loop].thisN or .thisTrialN, which aren’t working for you, for reasons I don’t understand. Notably, people have gotten this to work online with trials.thisTrialN in other threads, so I’m not sure why that didn’t work here. In any case, we just needed something that worked.

Yes, that’s a perfect next step. If that works you should be good to go.

1 Like

amazing, thank you ever so much for your assistance

Good that at least you figure out a working solution. The trialhandler’s behavior is really odd sometimes in JS,so bare in mind the safe side to go is to create your own custom variables which most of the times do the job right!

thank you for your help :slight_smile: it is weird how it was behaving and it my first foray into the pavlovia world, and the assistance was amazing. Hopefully i have no issues with output etc which is the next part of the journey and then linking the study with academic prolific etc. It is fun but frustrating also.