Conditions in experiment

Hi!

I am making some changes to my experiment and don’t have much experience with coding. I have 24 stimuli in the routine that would essentially be broken down in 12 trials each.

I have a current code that runs like this:

Begin Routine tab
if practiceLoop.thisN == 0:
score = 0

End Routine tab
if keyboard_name.corr:
score = score +1
if practiceLoop.thisN = 11 and score >= 8
practiceLoop.finished = True.

I would like to make some changes such as:

  1. An image will show if the participant scores < 8 correctly on the first 12 trials and they proceed to do the remaining 12 stimuli.
  2. In the remaining 12 stimuli, if they score < 8 correctly, they will skip the startGame and next trial routine and go back to the start for another condition. I have shown the current routine and loop in the builder view below.

Is there a way to achieve both of these changes with the current coding that I have or do I have to do something else to achieve them?

The logic in your code seems fine at first glance, but there are some syntax errors. practiceLoop.thisN = 11 won’t check whether practiceLoop.thisN is 11, it wil set it to be 11. Use == instead when checking for equality. On the same line you’re also missing a :

To show/hide an image according to a condition, you can use myImage.setAutoDraw() (set to True to show and False to hide) but if the image doesn’t need to be on screen at the same time as other components, the safest way is to put it in its own routine and then set continueRoutine = False in Each Frame if the image is not needed (aka end routine immediately)

Hi!

Oops that was my error for practiceLoop.thisN = 11 and a missing :

But because all of my stimuli file are listed in the same excel file, would creating a new routine mess that up?

Not so long as the new routine is in the same loop :slight_smile: The variable names (coming from Excel) are linked to the loop, not the routine

Oh okay that make sense!

So would it be something like this? “instr2_” is the new routine for the show/hide image

if resp.corr:
score = score + 1

if practiceLoop.thisN == 11 and score >= 8:
practiceLoop.finished = True

elif practiceLoop.thisN == 23 and score <=5:
practiceLoop.finished = False

does this code sound right? I would like that if participants scores less than 5 correct on the 2nd round of practice stimulus (i.e., 24th round score), they will stop this loop and move onto the next game instead of proceeding onto the next routine.

That seems reasonable at first glance :slight_smile: only thing is you might want to check thisN >= 11 rather than ==, otherwise it will only perform this check on the 11th trial rather than each trial after 11

Thanks for your help!

With regards to your suggestion on showing/hiding an image according to a condition, does the myimage in “myImage.setAutoDraw ()” refer to my file name? I wanted to try with the inclusion of a new routine but I’m not too sure where to include it.

I created the logic in each frame, does this seem correct?
if resp.corr:
score = score + 1

if practiceLoop.thisTrialN == 11 and score <= 5:
pract2Instr.setAutoDraw = True

As written this doesn’t do anything because practiceLoop.finished is False by default

Hi TParsons,

So I managed to get the image to show when I want it to. However, after the image is shown, the remaining trials doesn’t play. Is there any reason why?

Right now this is what i have, but once the continueRoutine = False is fulfilled, it doesnt go back to the start of the practiceLoop to play the remaining 12 trials in the routine. Did i miss out a step?

Could you upload the full psyexp? I’m guessing there’s something else at play here that I can’t see in the screenshot - it looks like a fairly complex experiment

Hi! Here you go! Do you need the corresponding excel files etc?

Combined game.psyexp (86.3 KB)

I’m also facing some issue on this.

so if my participant scores at least 8 correct on their 12th trial, they should move on straight to the test routine and skip the image. However, that’s not the case. The image is still presented and the loop continues even if I have included continueRoutine = False and practiceLoop.finished = True

This is a very complex design with a lot of points where this could be going wrong - I would recommend putting in some print statements at certain points to see what conditions are being met. e.g.

print("score greater than 8?", score > 8)

just so you can see what different variables are at at each point - it’s most likely that a conditional statement isn’t being hit when it should be

alright,

is it possible to show me an example for it? Will the print statements be shown on the screen or anything?

Print statements write whatever you give them to the stdout box in the Runner