Howdy, Stranger!

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

Supported by

[solved] error: coercing to Unicode: need string or buffer, int found

edited March 2014 in OpenSesame

Well, I already searched for this error and therefor I know where the problem may lie, but I can't find the mistake.

I have 16 fields, of wich 4 are getting filled over time, but only one is filled at a given time. So it's like 4 squares are popping up on the screen.

So i created 2 loops. one for the Question at the end and one for displaying my 4 filled blocks.

To draw the block at the rightpositon i use the following line :

draw rect 128 * [x] 128 * [y] 128 128 fill=1 penwidth=1 color=#bcbcbc show_if="always"
(teh spaces around the " * " are not actually in my sourcecode)

"x" and "y" are variables defined in the loop with these values:
x = [x_1];
y = [y_1];
for the first loop. in the secound it is "x_2" and "y_2" and so on until "x_4".

"x_1" and all the other are defined in the first loop. All with values from -2 to 1.

Here:
draw textline 64 * [frage_x] 64 * [frage_y] "[frage]" center=1 color=white font_family="mono" font_size=32 font_italic=no font_bold=no show_if="always" html="yes"

"frage_x" and "frage_y" are in the range from -3 to 3 and "frage" is either 1 or 2 or 3 or 4.

So apparently this error occurs with the values of "x" and "y". But how am I supposed to use negative values with these variables, because i need them for the negative area of the sketchpad.

Errorcode is:
Traceback (most recent call last):
  File "/usr/bin/opensesamerun", line 88, in <module>
    exp.run()
  File "/usr/lib/pymodules/python2.7/libopensesame/experiment.py", line 287, in run
    self.items[self.start].run()
  File "/usr/lib/pymodules/python2.7/libopensesame/sequence.py", line 55, in run
    self.experiment.items[item].run()
  File "/usr/lib/pymodules/python2.7/libopensesame/loop.py", line 146, in run
    _item.prepare()
  File "/usr/lib/pymodules/python2.7/libopensesame/sequence.py", line 107, in prepare
    self.experiment.items[_item].prepare()              
  File "/usr/lib/pymodules/python2.7/libopensesame/sketchpad.py", line 207, in prepare
    _item["x"], _item["y"], html=_item["html"]==u"yes")
  File "/usr/lib/pymodules/python2.7/openexp/_canvas/legacy.py", line 746, in text
    color=color, html=html)
  File "/usr/lib/pymodules/python2.7/libopensesame/html.py", line 192, in render
    if _x+dx > max_x + (max_x-x):
TypeError: coercing to Unicode: need string or buffer, int found

Comments

  • edited 8:13PM

    Hi,

    The error message is not very informative, but basically he problem here is that your trying to do arithmetic in OpenSesame script, which is not supported.

    Basically, you can refer to variables, like so ...

    draw textline [x] [y] "this works"
    

    ... but you cannot do any calculations with them, like so:

    draw textline 5+[x] 10*[y] "this doesn't work"
    

    If you want to do this, you'll have to use an inline_script before the sketchpad, where you do the calculations and save the result in a variable that you can use in the sketchpad.

    So for example an inline_script with the following script in the prepare phase ...

    exp.set('x128', 128*self.get('x'))
    exp.set('y128', 128*self.get('y'))
    

    ... and a sketchpad with:

    draw rect [x128] [y128] 128 128 fill=1 penwidth=1 color=#bcbcbc show_if="always"
    

    Does that make sense? OpenSesame script is just not a full fledged programming language like Python.

    Cheers,
    Sebastiaan

Sign In or Register to comment.