psychopy.org | Reference | Downloads | Github

Error reading ONE row from the condition file

In a loop I want a single repetition of a row from my condition file. Apparently, it is impossible to do in the online experiment. Instead of the value of a required variable in the condition file, only one letter (it is actually always a letter num 3) of that value is read and it obviously gives an error because this value should be a color:

origin: "Color", context: "when defining a color", error: "unknown named color: d"

This is how my variable with a needed row is generated:

prime_num = c_items[Math.floor(Math.random() * c_items.length)]

When I use two or more values in the array that I put into “Selected” field of the loop (prime_num), everything works – two lines are loaded and respective stimuli are presented. My temporary solution is to double the needed value and shorten the stimulus presentation time. But this is obviously a weird thing.

I’m on mac OS 10.15.3, PsychoPy version 2020.1.3 (the same problem occurred on 3.0.5).

Are you sure that the *random is doing what you want? If you are trying to populate an array there are notes on how to do so in my crib sheet (search the forum)

What precisely do you have in your selected rows field?

Hi! Thanks for the reply. Well, I print to console what is in prime_num in the end and it seems to be correct.

I don’t think the problem is with the randomisation, because I tried several things in the “Selected” field of the loop:

6 - doesn’t work
[6] - doesn’t work
6:10 - works
[6,7] - works
prime_num - doesn’t work
[prime_num] - doesn’t work
[prime_num, prime_num] - works.

1 Like

I think I went with primenum:(primenum+1) to select a single row.

a:b excludes b so a:a is nothing

Hi! thanks, it seems to work. However, it doesn’t work if I put prime_num:(prime_num+1) to the “Selected” field directly (in this case all the rows are presented). 5:6 works though – presenting row 5. But [5,6] presents both. Honestly, I don’t understand what happens in the “Selected” field. Everything goes in this line if I look at the JS code on gitlab:

trialList: TrialHandler.importConditions(psychoJS.serverManager, 'primes_list.xlsx', '[prime_num:(prime_num+1)]'),

But : is not even an operator in JS, right?

What does the auto translate do if you put useRows=prime:prime+1 in code and then use the variable in the loop definition?

You might need to try brackets round prime+1 or even have primeplus = prime + 1 on the previous line

hmmm, colon is a slicing operator in Python, right? So useRows=prime:prime+1 (with all brackets options) doesn’t work anyway. Auto-translate returns /* Syntax Error: Fix Python code */. It is possible that “Selected” field uses inserted information for slicing?

I’ve checked it now, this seems to be the case: https://www.psychopy.org/builder/flow.html#selecting-a-subset-of-conditions

However, this still doesn’t solve the problem. It works if I hardcode selecting variable like this:
useRows='6:7'. It seems that in the resulting js file, useRows should be still a meaningful argument for python slice function… The only way I made it work was the following python code:

useRows = str(prime_num) + ':' + str(prime_num+1)

, that was auto-translated to js.

That makes sense. The loop component needs the rows as a string variable