Howdy, Stranger!

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

Supported by

Timer

Dear all,

in my experiment I want to integrate a timer that counts down from 3 to 0 so the participants can get ready for the task and know when to start. Someone asked a similar question in an earlier discussion (since this discussion is marked as "solved" I post my question in a new discussion to prevent confusion) and @eduard wrote a great code for an inline script (thank you!). I used this script and modified it a bit because I don't want an exact clock timer, I just need a countdown (3, 2, 1, go!). Since I'm rather new to OpenSesame and I have never worked with python before, my inline script may not be flawless (but it does what I want it to do). Here is my version of the code (if I have made any mistakes or if the code is too complicated please let me know!):

 
from openexp.keyboard import keyboard
from openexp.canvas import canvas

cv = canvas(exp)

def timer2clock(timer):
    '''
    converts a plain integer representing the seconds left to a proper
    clock
    '''
    clock = str(timer)[:-5]
    # do the formatting
    if len(clock) == 2:
        clock = '0' + clock[:2] + '0' + clock[2:]
    elif len(clock) == 3:
        clock = '0' + clock[:2] + '0' + clock[2:]
    elif len(clock) == 4:
        clock = '0' + clock 
    return clock

# define parameters
start_time = self.time()
timer = 4000 
rest_time = 4000
clock = timer2clock(timer)
# show initial screen
cv.text(clock)
cv.show()

# update screen
while (rest_time > 0):
    # update time
    cur_time = self.time()
    rest_time = timer - (cur_time - start_time)
    clock = timer2clock(rest_time)
    # draw to screen
    cv.clear()
    cv.text(clock)
    cv.show()

# visualization of effects
if rest_time < 0:
    cv.clear()
    timer_canvas_achtung.prepare() #canvas defined in the prepare phase
    timer_canvas_achtung.show() #canvas defined in the prepare phase
    self.sleep(1000)
    cv.clear()
    timer_canvas_los.prepare() #canvas defined in the prepare phase
    timer_canvas_los.show() #canvas defined in the prepare phase
    self.sleep(1000) 

This code counts down from 3 to 0 and then it says "ready" (timer_canvas_achtung.show()) and then "go" (timer_canvas_los.show()). I defined the text for the canvas in the prepare phase because it allows me to define the font size of the text ("ready" and "go"). Everything works just fine my only problem is that the numbers of the countdown are very small (i.e. small font size). Is it possible to enlarge the font size for the numbers as well? I know I could choose a bigger font size in the "general properties tab" but I have a lot of instructions and I don't want the font size to get any bigger for the instructions. I want to change the font size for the numbers only. Does this make sense?

Thank you for your help!

Comments

  • Hi,

    Why not just place three sketchpads in your sequence, each with a duration of 1000ms, and displaying the numbers 3, 2 and 1 respectively? That's what I do usually.

    Cheers

    Josh

  • Dear Josh

    Thanks for your answer! I was thinking of that too but the reason I want to use an inline script is that OpenSesame (at least on my computer) has a problem with multiple sketchpads and doesn't display the sektchpads correctly (and since I want to use the countdown multiple times I would need at least 12 sketchpads and this could get messy...)

    Do you or does somebody else have a solution for changing the font size for the numbers in the countdown?

    Thanks!

  • I believe either fontsize or textsize is also an argument that you could add to the text() command (e.g. cv.text('3', textsize = 40)).

    It is quite problematic that you have trouble utilizing multiple sketchpads though.. what is it exactly that goes wrong when you place multiple sketchpads in a sequence?

    Cheers

    Josh

  • zsczsc
    edited May 2017

    Thanks for your answer! I'm not quite sure where I should add the command. For the text "ready" and "go" I added the command span size="50" (in the prepare phase) and this works just fine. For the numbers of the countdown however I don't know where I could add this command... I have a .text() for the clock but I don't think I can add the command there, right?

    Regarding the problem with multiple sketchpads: I have quite elaborate instructions for the tasks so I wanted to add some symbols to make it make it easier to understand. I figured the easiest solution would be to write the instructions into a textfile, make a screenshot and insert the screenshot into a sketchpad. I did this for every task I use in my experiment. When I go through the tasks I always have the same problem: the first time everything works but when I rerun the tasks then suddenly the sketchpads don't show up anymore, i.e. it just skips the instructions. That's why I use inline scripts for displaying instructions and this works just fine.. I don't know whether I did something wrong or if it's a bug..

    Cheers and thanks!

  • Nevermind I just figured it out :smile:
    I simply added the command: cv.set_font('sans', size) @Edwin posted in another discussion (once again thanks for the great support in this forum!). So now it looks like this:

    from openexp.keyboard import keyboard
    from openexp.canvas import canvas
    
    cv = canvas(exp) # initialize a canvas
    
    def timer2clock(timer):
        '''
        converts a plain integer representing the seconds left to a proper
        clock
        '''
        clock = str(timer)[:-5]
        # do the formatting
        if len(clock) == 2:
            clock = '0' + clock[:2] + '0' + clock[2:]
        elif len(clock) == 3:
            clock = '0' + clock[:2] + '0' + clock[2:]
        elif len(clock) == 4:
            clock = '0' + clock 
        return clock
    
    # define parameters
    start_time = self.time()
    timer = 4000 
    rest_time = 4000
    clock = timer2clock(timer)
    # show initial screen
    cv.text(clock)
    cv.set_font('sans', 100) #font size for the numbers 
    cv.show()
    
    # update screen
    while (rest_time > 0):
        # update time
        cur_time = self.time()
        rest_time = timer - (cur_time - start_time)
        clock = timer2clock(rest_time)
        # draw to screen
        cv.clear()
        cv.text(clock)
        cv.set_font('sans', 100)
        cv.show()
    
    # visualization of effects
    if rest_time < 0:
        cv.clear()
        timer_canvas_achtung.prepare()
        timer_canvas_achtung.show()
        self.sleep(1000)
        cv.clear()
        timer_canvas_los.prepare()
        timer_canvas_los.show()
        self.sleep(1000)
    

    If someone sees a mistake please let me know,
    cheers and thanks!

  • edited May 2017

    Hi zsc,

    Thanks for sharing! You could also use a loop item and one sketchpad item like in my attached example. You can reuse the timer by using a linked copy of the loop. Like I did after the AnyKey sketchpad.

    Are you using OpenSesame version 3.1.6 because I know version 3.1.5 had some sketchpad bug....

    Best,
    Jarik

  • Dear Jarik

    Thank you for sending me an alternative example! I will definitely try it out, could be an even easier way to get a countdown :)

    I have the newest version (3.1.6) of OpenSesame.. But it is possible that I made a mistake somewhere and just didn't realize it.

    Anyway, thanks again for your help!
    Cheers

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