psychopy.org | Reference | Downloads | Github

Problem reading condition data with block and trial loops

OS (e.g. Win10): Win 10
PsychoPy version (e.g. 1.84.x): 3.0.3
Standard Standalone? (y/n) If not then what?: Y
What are you trying to achieve?:

I am trying to make the below work based on the post here: Blocks of trials and counterbalancing

Below is a screenshot of the simple loop I’m trying to achieve:

What I’m trying to do is for each block, have the trials loop access a different excel file with the stimuli for those trials.

My block definition looks like this:

and my trials definition looks like this:

“opponent_condition” is a column inside ‘choose_opponent.xlsx’ which has a list of filenames.xlsx. Now, within each opponent_condition file is a bunch of parameters. For example, there is one called ID_text which i would like to have in a text component on each trial. So in the text box I type $ID_text.

However, when I run the experiment I get the following error:

image

I haven’t found a satisfactory resolution to that error. However, I did try something based on a different answer (which annoyingly I now can’t find again). It basically said to delete the reference to the condition file in the outer block and instead define the block files in the Begin Experiment tab (i.e. block = [‘name1.xlsx’, name2.xlsx]), and then in the trials condition box, put: $block.pop(). When I do that I get this error:

image

Any recommendations welcomed. I have read and re-read the post I linked above and can’t figure out what I’m doing differently, so I’m quite confused.

Thanks in advance.

@Anthony I am assuming what you are trying to achieve is you want the trials loop to run upto opponent_condition from the file choose_opponent.xlsx. For that you would have to enter in the Conditions tab as ‘choose_opponent.xlsx’ and in the random seed $ as $opponent_condition.

I hope that helps!

Hi,

Thanks for your reply. Unfortunately that hasn’t done the trick. ‘opponent_condition’ is a column header in the choose_opponent.xlsx file. The column then lists other excel files which normally be the conditions for the trials loop (if there was not the outer, blocks, loop). I’m trying to get the trials loop to read the condition from the choose_opponent file, so that it can then loop through the information in the correct opponent_condition file. I’m not sure entering something in the random seed field is the correct approach, at least not as stated in the post I linked to in the original question.

Any other thoughts?

Cheers,
Anthony

Oh ok. I suppose I had mistakenly read your query. Apologies for that!

In order to randomize the other excel files that are written in one excel file, you would essentially need a code component. I would recommend looking into Randomly present all blocks and then in a reverse order. You would need to redesign the code according to your need.

Also, check if you have set the text box ‘Text’ column set at ‘set every repeat’ or else it will not loop. And as @dvbridges pointed out, there is a simple error of calling ‘opponent_file’ as ‘opponent_condition’. That should do the trick!

Hope this helps!

@Anthony, not sure if you need to reload your conditions file, but it appears in your image that your column is labelled opponent_file, but you are calling opponent_condition, and that may be why you get your not defined error.

1 Like

@dvbridges, thanks - I had already caught that mistake and changed it. I’m still getting the below error though:

image

Ok, perhaps something is not working with the Excel sheets. I have an example of nested loops already made. Have a look at this simple example, and see how yours differ. I would make sure my conditions sheets have all the correct information as well.

In the outer Blocks loop, I open the orderA.xlsx sheet, which has entries for A.xlsx and B.xlsx. A and B sheets have text entries for formatting the text component.

nestedLoops.psyexp (6.8 KB)
OrderA.xlsx (9.2 KB)
A.xlsx (7.8 KB)
B.xlsx (7.8 KB)

As far as I can tell I have everything set up exactly as you have. Very odd.

However, I’ve now written code as outlined by the link @Shardul_Shankar provided and this method is working now. It’s the same approach I used in the second half of my original post, but this time it worked. There were a few changes in the meantime so I’m not 100% sure what is different.

Thanks for your help. It’s a shame I can’t get the simpler, GUI approach to work. I’m not averse to coding, I just don’t like having perplexing questions left over!

Thanks for this. This is the link I was referring to in the second half of my original post but couldn’t find it again!

I’ve used this now and it is working. I’m not 100% what changed from this iteration to the one that didn’t work before, but such is the nature of these things sometimes!

Thanks for you help.

Hi @dvbridges I am wondering if you can upload the nestedLoops.psyexp again. I am not able to download it, after trying different browser.

Hi @Miao, if you click the link to the psyexp file, copy the text and paste it into a text editor e.g., PsychoPy Coder, then save that file with a .psyexp file extension, this should work.

Okay, many thanks~

Hi David @dvbridges,

Your shared experiment, and thereby my experiment module, has stopped working. Can you tell where the new issue is, and what the fix is?

Much appreciated in advance.