Welcome!

Sign in with your CogSci, Facebook, Google, or Twitter account.

Or register to create a new account.

We'll use your information only for signing in to this forum.

Supported by

Sketchpad Variable TypeError: coercing to Unicode: need string or buffer, int found

erbrainpsyerbrainpsy Posts: 2
edited December 2017 in OpenSesame

Hi guys,
i'm creating an experiment where three images are displayed on a sketchpad at once. Subjects have to decide for one of the images with a keypress. Based on their choice, i want to highlight the chosen image by drawing a rectangle around it. The location of the rectangle thus has to be varied on it's x-coordinate. Therefore i created a variable in an inline script that is set to one of the three possible values like so:

draw rect color="[rect_color]" fill=0 h=390 penwidth=6 show_if=always w=260 x="[rect_x]" y=-195 z_index=0

where [rect_x] is specified before like this in a script:

rect_loc =[-430,-130,170]

if exp.response == 'v':
    exp.set("rect_x", rect_loc[1])
elif exp.response == 'y':
    exp.set("rect_x", rect_loc[0])
elif exp.response == 'm':
    exp.set("rect_x", rect_loc[2])

When running the script, i get the following error:
Traceback:
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libqtopensesame\misc\process.py", line 140, in run
    exp.run()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\experiment.py", line 413, in run
    self.items.execute(self.var.start)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 91, in execute
    self.run(name)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 106, in run
    self[name].run()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\sequence.py", line 51, in run
    self.experiment.items.run(_item)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 106, in run
    self[name].run()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\loop.py", line 337, in run
    self.experiment.items.execute(self._item)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 91, in execute
    self.run(name)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 106, in run
    self[name].run()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\sequence.py", line 51, in run
    self.experiment.items.run(_item)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 106, in run
    self[name].run()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\loop.py", line 337, in run
    self.experiment.items.execute(self._item)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 91, in execute
    self.run(name)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 106, in run
    self[name].run()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\sequence.py", line 51, in run
    self.experiment.items.run(_item)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 106, in run
    self[name].run()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\loop.py", line 337, in run
    self.experiment.items.execute(self._item)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 90, in execute
    self.prepare(name)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 122, in prepare
    self[name].prepare()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\sequence.py", line 124, in prepare
    self.experiment.items.prepare(_item)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 122, in prepare
    self[name].prepare()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\sketchpad.py", line 117, in prepare
    element.draw()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\sketchpad_elements\_rect.py", line 65, in draw
    penwidth=properties[u'penwidth'])
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\openexp\backend.py", line 180, in inner
    retval = fnc(self, *arglist, **kwdict)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\openexp\_canvas\xpyriment.py", line 140, in rect
    self.line(x, y, x+w, y)
TypeError: coercing to Unicode: need string or buffer, int found

At this point, i don't know why a string or buffer is expected as a value for the x-coordinate.
I've read about similar problems concerning this kind of TypeError in other threads, but none of them seemed to help me solve my issue.

Thanks in advance for all comments.
Elias

Comments

  • sebastiaansebastiaan Posts: 2,950

    Hi Elias,

    I suspect that rect_x is simply assigned another value, which is Unicode (text), later in the experiment. Could that be it?

    The error is most definitely due to either the width or the x-coordinate of the rectangle being Unicode. And based on your code, I'd say the x-coordinate is the more likely candidate.

    Cheers,
    Sebastiaan

    Thanked by 1erbrainpsy

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • Hi Sebastiaan,
    thank you, for your quick reply!
    My script didn't assign any unicode to the [rect_x] variable later on. However, i just solved the problem by defining [rect_x] beforehand, outside the if-statement. I just assigned a random int, which gets now updated by the if-statement. This somehow did the trick!
    Chapeau to the great support around here!
    Best,
    Elias

Sign In or Register to comment.