A new way of working with loop variables

Is it possible to use a previously declared list / dictionary in a loop, instead of a csv table. Question for developers: is it possible to add a string with the variable name along with “conditions”?

I quite often either declare lists at the start of the experiment or preload items into lists for use in later loops. Have a browse through some of my online demos.

Please could you clarify your second question?

Actually, I do get this. It’s about the desire to provide the name of a variable into the dialog box that isn’t then treated as a path name. I’ll look into it. Two options spring to mind:

  1. If the function importConditions receives a list as its first argument it could just return that list with no further processing. This way the code generated in Builder wouldn’t need to change at all. The downside is that it’s a slightly weird thing to put into the function
  2. We could change the code generated by Builder to do the checking within the script (rather than within the function). This seems more “right” but adds lines to the script for a rather uncommon use-case.

We’ll have a chat internally about whether this is the most elegant solution

In the meantime, I think you can hack your own solution on the basis of option (1) using a Code Comp. I think this code in any Begin Experiment section should get you the results you need:

# keep track of original
_importConditions = importConditions
# create a new func with same call structure to be used in this study
def importConditions(fileName, returnFieldNames=False, selection=""):
    if type(filename) == list:
        return filename
    else:
       return _importConditions(filename, returnFieldNames, selection)
1 Like