Howdy, Stranger!

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

Supported by

[solved] show sketchpad for set time even if response is made and feedback arrives

edited March 2014 in OpenSesame

Hi, I a very similar problem to the one exposed here, but from that description I din't unedrstand how it has been solved and since it was marked as "solved" I thought to open a new post.

Basically, I need that during a single trial, lasting for expample 6 sec, the subject should be able to give mouse responses and receive a different feedback (visualize an image for 500ms) for each response without ending the trial until 6 sec elapsed.

This is the inline code that follows a sketchpad (named 'choice') which lasts 0 sec, in which different squares are visualized as possible choices. The subject is required to choose with a mouse-click on one:

from openexp.mouse import mouse
my_mouse = mouse(exp)
my_mouse.set_visible()
my_mouse.set_pos(pos=(660,260))
my_mouse.set_buttonlist( [1] )
my_mouse.flush()

trial = exp.get('choice_cond')

button, position, timestamp = my_mouse.get_click()
x, y = position

from openexp.canvas import canvas
my_canvas = self.copy_sketchpad('choice')

uno = exp.get_file(u'/media/File/experiment/stim/O1.jpg') # feedback one
due = exp.get_file(u'/media/File/experiment/stim/O2.jpg') # feedback two
delay = 500

if trial == (12):

    if x > (114) and x < (294) and y > (300) and y < (480):
        exp.set('response', 1)
        exp.set('response_____keyboard_response', "R1")
                    # show the appropriate feedback
        my_canvas.image(uno, center=True, x=None, y=600, scale=0.1) 
        my_canvas.show() 

    if x > (432) and x < (612) and y > (300) and y < (480):

        exp.set('response', 1)
        exp.set('response_____keyboard_response', "R2")
                    # show the appropriate feedback
        my_canvas.image(due, center=True, x=None, y=600, scale=0.1) 
        my_canvas.show() 

    if (x < (114) and x > (294)) or (x < (432) and x > (612)) and (y < (300) or y > (480)):
        exp.set('response', 0)

 self.sleep(6000)  # to make each trial end after 6 sec

I've tried to use self.sleep() after my_canvas.image to set the duration of this image but, of course, it ends the whole canvas.

I know there is probably more than one wrong thing in this script, but I cant' figure it out!Please help!

Thanks!

Comments

  • edited March 2014

    I have improved the code in this way and it seems to work:

    start_time = self.time()
    trial_duration = 10000
    lastRes1_time = 0
    lastRes2_time = 0
    lastRes3_time = 0
    lastRes4_time = 0
    import random
    schedule = random.randint(2000,3000)
    
    
    from openexp.mouse import mouse
    my_mouse = mouse(exp)
    my_mouse.set_visible()
    my_mouse.set_pos(pos=(660,260))
    my_mouse.set_buttonlist( [1] )
    my_mouse.flush()
    
    from openexp.canvas import canvas
    sketch = self.copy_sketchpad('choice')
    my_canvas = self.copy_sketchpad('choice')
    # Determine the absolute path:
    no = exp.get_file(u'/media/experiment/stim/no.jpg')
    uno = exp.get_file(u'/media/experiment/stim/O1.jpg')
    due = exp.get_file(u'/media/experiment/stim/O2.jpg')
    
    # Get ... as python variables
    trial = exp.get('choice_cond')
    
    
    while self.time() < start_time+trial_duration:
    
    
        # Wait for a mouse click
        button, position, timestamp = my_mouse.get_click()
        x, y = position
    
    
    ##############################
        if trial == (12):
            exp.set('correct', "RR")
                # button 1
            if x > (114) and x < (294) and y > (300) and y < (480):
                    exp.set('response', 1)
                    exp.set('response_____keyboard_response', "R1")
                    if  self.time() > lastRes1_time + schedule:
                        my_canvas.image(uno, center=True, x=None, y=670, scale=0.15)
                        lastRes1_time = timestamp
                        my_canvas.show()
                        self.sleep(600)
            # button 2
            if x > (432) and x < (612) and y > (300) and y < (480):
                    exp.set('response', 2)
                    exp.set('response_____keyboard_response', "R2")
                    if  self.time() > lastRes2_time + schedule:
                        my_canvas.image(due, center=True, x=None, y=670, scale=0.15)
                        lastRes2_time = timestamp
                        my_canvas.show()
                        self.sleep(600)
    
        sketch.image(no, center=True, x=None, y=650, scale=0.01)
        sketch.show()   
    

    is this the best solution?
    I hope it can be helpful for someone!

  • edited March 2014

    Hi Sara,

    Depending on what you want to do, you seem to have come up with a very good solution. Keep in mind that with your script, the interaction continues to run after the first click. This means that participants can alter their choice after clicking.

    If you do not want to do so, the following example shows a single-click-and-wait procedure:

    # put the beginning of you script here, up until the while loop
    
    # get the starting time
    start_time = sketch.show()
    
    # wait until a buttonpress is made
    button = None
    passed_time = None
    while button == None and passed_time < trial_duration:
        # check for button presses
        button, pos, click_time = my_mouse.get_click(timeout=1)
        # check if button 1 was clicked
        if (114 < x < 294) and (300 < y < (480):
                    exp.set('response', 1)
                    exp.set('response_____keyboard_response', "R1")
        # check if button 2 was clicked
        elif (432 < x < 612) and (300 < y < (480):
                    exp.set('response', 2)
                    exp.set('response_____keyboard_response', "R2")
        # check if button 1 was clicked
        else:
                    # reset button
                    button = None
        # calculate the passed time
        passed_time = click_time - start_time
    
    # reset the screen
    sketch.clear()
    # show a blank screen
    end_time = sketch.show()
    passed_time = end_time - start_time
    
    # wait for a bit
    self.sleep(trial_duration - passed_time)
    
  • edited 2:54AM

    Actually, I do want them to click several times (and, thus, make more than one choice) during a certain time interval while visualizing the same sketchpad) and subsequently go to the next trial. Thus, in this case, I don't need to reset the screen or to show a blank screen.
    I did not specified that, in this task, there are several buttons and in each trial two of them are available.

    Than you for the optimized script. By looking at it I have improved some things in mine!

  • edited 2:54AM

    Excellent! I just included the script for the single button responses for future reference, it was by no means a comment on your design :)

    Good luck with testing!

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