| Reference | Downloads | Github

Simulus position list via conditions file doesn't convert to javascript (builder)

URL of simple version of experiment that replicates the issue:

Description of the problem:

The experiment linked above replicates a problem I encountered with an experiment in which the positions to present stimuli (e.g., [0, 0]) are specified in a parameter (named ‘textlocation’) in a conditions file. When running the experiment in Builder, simply putting the textlocation parameter name in the position field of the text stimulus works fine (so the above experiment runs fine in Builder). But when running online, it results in the following error with converting the list from a string to a javascript numerical array:

Error: Unfortunately we encountered an error: { “origin” : “util.toNumerical”, “context” : “when converting an object to its numerical form”, “error” : “unable to convert: (0, 0) to a number.”}

The same error occurs if a list or tuple is specified in the conditions file.

PARTIAL SOLUTION: For a list, the problem running online is fixed by specifying the position as: JSON.parse(textlocation). But this breaks the Builder version. So it appears to be a problem with converting from python to javascript for running the experiment online?

Also, the JSON.parse solution didn’t work if the conditions file contains tuples instead of lists.

I think the problem is that the position tuple is loaded as a string from the conditions file, so cannot be interpreted as a number. If you instead have separate columns for x and y, and just add the relevant numbers, you can get around this issue. E.g., you have two cols in your conditions file, posX and posY, and in your shape stim you set the position to update on every repeat, with the following entry: [posX, posY].

Just for info, JavaScript will not read a tuple as a list in the same way Python does. You need to use the array format (square brackets).

1 Like

Great, thanks. Separating into two numerical columns for X and Y worked.

(I deleted the listerror experiment linked to above.)

Excuse me, but how can you enter any combined parameters to the Builder Position input, or anywhere else? I tried and failed multiple times, like:

entering in builder: ($place1, $place2)
error in runner:
text_3.setPos(($place1, $place2))
SyntaxError: invalid syntax

EDIT: Now I understand, that a single $ sign switches to code-mode, rather than just expose variables.
the above problem was solved by entering $(place1, place2)


I had the exact same issue and fixed it (by putting $[xloc,yloc] into the builder), but i’m not sure how to accommodate this into the following code component:

Begin Experiment:
obs_dict = {}

Begin Routine:

    for image in trials.trialList:
        image = image['object']
        obs_dict[image] = 0

correct = False

loc = trials.thisTrial['loc']
image = trials.thisTrial['object']
if obs_dict[image] == 2:
    if 0 in obs_dict.values() or 1 in obs_dict.values():
        trials.finished = True

End Routine:

    if mouse.y[0] in range(loc[1]-150, loc[1]+150):
        correct = True

if correct == True:
    obs_dict[image] +=1
elif correct == False and obs_dict[image] == 1:
    obs_dict[image] = 0

Where “loc” was just a condition in a .csv file composed of co-ordinates which i’ve now broken down into two numerical conditions called “xloc” and “yloc”

Any help much appreciated,