edrevolution / pywright

Automatically exported from code.google.com/p/pywright
0 stars 0 forks source link

Tutorial for timer #92

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I uploaded a 0.9861 - it should fix the bug in turnabout substitution. It 
forces pywright to go back to the fixed framerate mode.

In 0.986 the timer works, but if you try and check the value of the timer with 
"is timer = 60" etc it won't work. 0.986 runs at a variable framerate meaning 
that the value of the timer may be a decimal, and until now wrightscript only 
dealt with integers. I would like to keep it this way, so I'll see if I can 
work out a compromise somehow.

Tap:
Timers don't carry over across scripts, but the variables they use do. For all 
the scripts where the timer happens, you will need to restart the timer object. 
The actual time left is stored in a variable, so when you start up a new timer, 
you can set it's ticks to that value.

The command 'timer 60 mymacro' will set _timer_value_mymacro = 60. On the next 
script, if you call 'timer $_timer_value_mymacro mymacro' it will start a new 
timer that has the number of ticks that were left. If I were you I would make a 
macro called starttimers that does this, and just put it at the top of each 
script. There is actually a way to define code which automatically is always 
run on a new script but it's complex and could present issues.

Note that if you use 'clear' all timer objects will be deleted as well. You can 
cause timers to be paused this way.

60 ticks = 1 second, so 1 tick = 1/60 seconds. 7200/60 = 120 seconds, or 2 
minutes. You could display a timer in minutes with a little bit of math.

With textblock if the first argument is color= you can set the color of the 
whole text. The text itself doesn't support coloring.

Check core/macros/defaults.mcro, font_defaults for all of the font variables. 
Textblock uses _font_block, and you can set both the actual font file to use, 
and the size.

Example code: Shows timer in minutes:seconds with color, and in a big font

Code:
set _font_block_size 16
macro printme
print HI
endmacro

macro timer_display
delete name=td
set seconds $_timer_value_printme
divvar seconds 60
set minutes $seconds
divvar minutes 60
set minsec $minutes
mulvar minsec 60
set secleft $seconds
subvar secleft $minsec
joinvar timetext $minutes : $secleft
textblock 0 0 100 50 color=070 name=td $timetext
print $minutes $seconds $minsec
endmacro

timer 7200 printme
gui Wait run=timer_display

This code will work on 0.9861.

Original issue reported on code.google.com by saluk64007@gmail.com on 6 Aug 2011 at 8:11

GoogleCodeExporter commented 9 years ago

Original comment by saluk64007@gmail.com on 16 Jan 2014 at 11:12