[solved] passing an inline script variable to a sketchpad
I'm very new to both OS and Python and I'm trying to code a spatial cuing experiment with four possible cue/target locations. I define a cue and target position randomly on each trial (with some restrictions determined by the "val" variable) with the following inline script appearing as the first item in the trial sequence:
import random
positions = list(range(4))
random.shuffle(positions)
var.target_pos = positions[0]
if var.val == 1:
var.cue_pos = var.target_pos
else:
var.cue_pos = positions[1]
xcoord = [160, 160, -160, -160]
ycoord = [-160, 160, 160, -160]
trialxcoord = xcoord[var.cue_pos]
trialycoord = ycoord[var.target_pos]
That works great at selecting the appropriate x,y coordinates as confirmed when I print the variables in the debug window. However, when I plug trialxcoord and trialycoord into a subsequent sketchpad script like this:
draw image center=1 file="cue.png" scale=1.5 show_if=always x=trialxcoord y=trialycoord z_index=0
I get the following error:
TypeError: coercing to Unicode: need string or buffer, int found
I'm sure I'm doing something incredibly stupid/basic, but any help would be appreciated!
Comments
Hi Chip,
To indicate that a string is a variable name, rather than a literal string, you put square brackets around it. Like so:
In addition, this only works for experimental variables, that is, the ones that are prefixed with
var.in Python code. So this doesn't work:... But this would:
Does that make sense?
See also:
Cheers,
Sebastiaan
PS. We should really add a contingent-capture experiment to the examples. ;-)
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
Great program btw!!!!
Thanks for the quick response . . . that fixed it! I knew it had to be something about the syntax. And yes, adding a contingent capture example would be nice (although you should check with the boss first)
Thanks again,
Chip