Howdy, Stranger!

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

Supported by

[solved] String input problem

edited May 2013 in OpenSesame

Hi!

I'm doing a test were the participants inputs a string of numbers. I borrowed your code from this thread and got it to work as intended except for one case. The repsonse seem to be interpreted as a value so zeros in the without preceeding numbers in the response are discarded. I've tried handling the input as a string but can't figure out what I'm doing wrong.

from openexp.canvas import canvas
from openexp.keyboard import keyboard
my_canvas = canvas(self.experiment)
my_keyboard = keyboard(self.experiment)
resp = str("") # Here we store the response
while True:
    # Get a keyboard response
    key, time = my_keyboard.get_key()
    # keyboard.to_chr() converts the keycode to a description,
    # like 'space' or 'return'. If return is pressed the loop
    # should be exited.
    if my_keyboard.to_chr(key) == "return":
        break           
    # Handle backspace by removing the last character
    if my_keyboard.to_chr(key) == "backspace":
        resp = resp[:-1]    
    else:
        # The built-in chr() converts the keycode to a character,
        # like ' ' and '/'.
        resp += my_keyboard.to_chr(key)
    # Copy the canvas from a sketchpad called 'my_sketchpad' and
    # overlay the response
    my_canvas.copy(self.experiment.items["my_sketchpad"].canvas)
    my_canvas.text("mata in de 4 sista siffrorna", x=0,y=-64)
    my_canvas.text(resp)
    my_canvas.show()    
# Save the response
self.experiment.set("response", resp)

Comments

  • edited May 2013

    Hi Benno,

    Welcome to the forum!

    Indeed, OpenSesame automatically decides what type a variable is, as described here:

    In this case, this is actually not what you want, because when OpenSesame decides that a variable is numeric, the leading zeros will be lost. There are various ways around this, for example by prepending a '_' to the response:

    self.experiment.set("response", "_%s" % resp)
    

    In this case, 0001 will be saved as _0001, and OpenSesame will not think it's an integer. Whether this is a suitable approach depends on how you intend to use these responses later on. If it's just for logging purposes, prepending an '_' should be fine, I think.

    As an aside, forms provide a simpler way to collect text input. Depending on what you want to do, you could consider using a form instead of this inline script (but whatever works for you, of course).

    Good luck, and let me know if this doesn't answer your question.

    Cheers!
    Sebastiaan

  • edited 5:27PM

    Your sollution works well for my problem.

    Thanks for the quick response. :)

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