问题
I want to trigger an alarm when the GUI starts. I can't see what's the equivalent of load event of other language in Rebol VID, so I put it in the periodic handler which is quite circumvoluted. So how to do this more cleanly ?
alarm-data: none
set-alarm: func [
"Set alarm for future time."
seconds "Seconds from now to ring alarm."
message [string! unset!] "Message to print on alarm."
] [
alarm-data: reduce [now/time + seconds message]
]
ring: func [
"Action for when alarm comes due."
message [string! unset!]
] [
set-face monitor either message [message]["RIIIING!"]
; Your sound playing can also go here (my computer doesn't have speakers).
]
periodic: func [
"Called every second, checks alarms."
fact action event
] [
either alarm-data [
; Update alarm countdown.
set-face monitor rejoin [
"Alarm will ring in "
to integer! alarm-data/1 - now/time
" seconds."
]
; Check alarm.
if now/time > alarm-data/1 [
ring alarm-data/2
;alarm-data: none ; Reset once fired.
]
][
either value? 'message [
set-alarm seconds message
][
set-alarm seconds "Alarm triggered!"
]
]
]
alarm: func[seconds message [string! unset!]][
system/words/seconds: seconds
if value? 'message [
system/words/message: message
]
view layout [
monitor: text 256 ""
rate 1 feel [engage: :periodic]
button 256 "re/start countdown" [
either value? 'message [
set-alarm seconds message
][
set-alarm seconds "Alarm triggered!"
]
set-face monitor "Alarm set."
]
]
]
回答1:
If the question is how to make something happen when the gui starts, you can do this
view layout [ text "Here's my layout"
do [ .... initialization code ... ]
]
来源:https://stackoverflow.com/questions/2895458/a-more-elegant-way-to-start-a-multithread-alarm-in-rebol-vid-whats-the-equiv