Howdy, Stranger!

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

Supported by

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

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

  • 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

  • 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.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games