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
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
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:
If someone sees a mistake please let me know,
cheers and thanks!
Hi zsc,
Thanks for sharing! You could also use a
loop
item and onesketchpad
item like in my attached example. You can reuse the timer by using a linked copy of theloop
. Like I did after the AnyKeysketchpad
.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