Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Possible to populate sketchpad in sequence using array?

edited June 2014 in OpenSesame

Suppose there are global arrays for target items and correct responses that have been created for a block of N trials. The reason this is being done is because the items and responses have to follow various constraints and that simple randomization will not do.

Once these arrays exist, one can loop through the sequence containing the sketchpad. However, is it possible for the sketchpad to display item[k] on the kth trial in such a loop and validate the response using the response from the kth item of the responses array? If so, how can this be done?

I thought that having an inline script element in the sequence would work. That is, in this script element two variables (target and response) can be defined using array access and an iterator. But I can't seem to get this to work properly and I think this has something to do with the distinction between prepare and run phase and how things work under the cover. I am just using a for loop to run the prepare and run phases of the sequence as recommended in an earlier forum post.

Comments

  • edited 2:23PM

    The answer is Yes. One has to use exp.set within a for loop as below. However the concerned set variables need to be set at least once outside the loop (say in a previous inline script). Arrays need to be global when defined and initialized. Otherwise it is not recognized in the sequence (probably outside the scope). This question is resolved.

    for i in range(exp.get('blocksize')):
            exp.set('trialstimulus',items[order[i]])
            exp.set('trialresponse',responses[order[i]])
            exp.items["trialsequence"].prepare()
            exp.items["trialsequence"].run()
    
Sign In or Register to comment.