psychopy.org | Reference | Downloads | Github

Problem with image stimulus repeating twice

What are you trying to achieve?:
Hi. I’m trying to run a cued object naming task, where I present a cue (in the form of a red or a green square) after the fixation cross to indicate the language that the participant has to name the image (which follows the cue) in.
I have the stimulus images in an excel sheet, which is attached in the conditions file of the loop as shown in the flow below.

My flow looks as follows:

There is a code component in the begin experiment tab of the cue_colour routine which is the follows:
cue="."

if $order="red.png":
    cue="red.png"
else:
    cue="green.png"

I need the cue to appear in a random order, along with the randomisation of stimulus image that appears after the cue. I also need the objects to appear only once.
This is the problem: The image files (stimulus) are now appearing twice in a row

I would really like some help with resolving this issue, since I’m approaching a deadline soon.

Your if statement has a few problems:

  1. It should be in Begin Routine, not Begin Experiment
  2. The $ sign tells components to treat the following text as code, and should therefore not be used for this purpose in code components.
  3. When testing for equality in code, use == instead of =

Hi,

I installed the latest version of psychopy and made the experiment again.
I used the same code components as my earlier experiments but it is now showing a python syntax error.
I’m attaching images below for reference.

image

image

Could you please point out where the problem lies, since I’m not that familiar with coding?

Is cue also the name of your image component, as opposed to the image variable name?

continueRoutine = True is the default, so this code won’t do anything when fixed. You probably want != and False.

This is what my routine looks like:

I use a code component in the previous routine to call the .csv file that is used to randomly display the two cue images. It looks like this:

image

and the .csv looks like this:
image

The error says that it is a python syntax error in line one of the begin routine tab, which is:
if cue == “red.png”:

Since you have a component called cue_2, then I suspect cue exists as a component elsewhere. This routine looks like a copy of a previous one. I would recommend that you change cue to something else here.

In your code you should only have one equals sign when setting the cue image as red or green. The double-equals only occurs when testing for equality (in the if statement).

Thanks! Solved the issue with the other code but this one still shows an error.

This is the Python code I use in my Trial Switching demo

myData = data.TrialHandler(
nReps=1, 
method='sequential', 
extraInfo=expInfo, 
originPath=-1, 
trialList=data.importConditions(conditions), 
seed=None, 
name='myData')

where conditions = "Stims_rand.xlsx"

Hi, I tried this. But the error still shows up in the code that I used previously, even if the code does not exist anywhere!

image

This is the code that I replaced it with:
myData = data.TrialHandler(
nReps=1,
method=‘random’,
extraInfo=expInfo,
originPath=-1,
trialList=data.importConditions(“nabonda.csv”),
seed=None,
name=‘myData’)

Since your code doesn’t mention cuefile.csv, might the error be related to one of your loops or a different import statement?

I have only one import statement which is shown in the picture above. I replaced it with the code that you suggested and also changed the name of the .CSV file.
The problem is, the error still shows in the old code, even if i have removed it and replaced it with the one you suggested.

After you synchronise your latest changes, you may find that your browser will often still run an earlier version of your code. This is due to the old code being present in your cache. Try refreshing your experiment start page using Ctrl-F5, Ctrl-Shift-R or equivalent). You may also need to disable the cache via Network conditions in the browser console. When you have developer tools showing you can also press and hold the page refresh icon and select Empty Cache and Hard Reload.

Other alternatives are using an incognito tab or a different browser or device.

Your participants will not normally experience this issue, since they should not have an earlier experiment of your code in their cache, unless they have been helping you pilot your study.

I’m trying to do the experiment in a different PC altogether.
Here, when I’m starting to write a If loop in the code component where the setting is set to Auto → JS, it shows an error as follows:

It seems like the word if itself is causing an error. Any idea how to fix it?

if by itself is not valid syntax. You need to complete the if statement.

I managed to fix the errors and sync it to pavlovia. Now this is the error that I get:

image