currently timers can be created ON LY if you have a window,, but in many case you never open window (games etc)
additionally a "delay()" would be nice
i know javascript has not but spider can simulate it with settimeout internally and give to high level (basic level) a Delay
AddScreenTimer
AddScreenTimer
Christos
Re: AddScreenTimer
Hello plouf,
SpiderBasic seems to store the data for the timer on the window so I don't know if this can be detached from the window at all.
The following is a dangerous and maybe wrong hack. I have little to no knowledge of JavaScript and have extracted the necessary information for this hack from the compiled file "spiderbasic.js".
Creating a timer without a window seems to work (although I don't know if the hack messes up anything internally). But a RemoveTimer does not work like this. I was not able to adjust the JavaScript parameters of the RemoveTimer() function, so that they work without a window. Maybe the Chuck Norris of JavaScript (Peter) can help?
RemoveTimer() in JavaScript: function(b,a){var c;if(c=spider.window.a.Get(b)){var e=""+a;c.d[e]&&(clearInterval(c.d[e]),delete c.d[e])}}
Maybe this will help you as a workaround.
Markus
SpiderBasic seems to store the data for the timer on the window so I don't know if this can be detached from the window at all.
The following is a dangerous and maybe wrong hack. I have little to no knowledge of JavaScript and have extracted the necessary information for this hack from the compiled file "spiderbasic.js".
Creating a timer without a window seems to work (although I don't know if the hack messes up anything internally). But a RemoveTimer does not work like this. I was not able to adjust the JavaScript parameters of the RemoveTimer() function, so that they work without a window. Maybe the Chuck Norris of JavaScript (Peter) can help?
RemoveTimer() in JavaScript: function(b,a){var c;if(c=spider.window.a.Get(b)){var e=""+a;c.d[e]&&(clearInterval(c.d[e]),delete c.d[e])}}
Code: Select all
; Timerevent without window
Procedure TimerEvents()
Debug "Timer event: " + EventTimer()
EndProcedure
Global.i timerno = 0, interval = 1000
; 12 = #PB_Event_Timer
; -65535 = #PB_Ignore
; Add the timer
! setInterval(function(){spider.event.Send(12,-65535,v_timerno,0)},v_interval)
BindEvent(#PB_Event_Timer, @TimerEvents())
; This does not work (RemoveTimer)
; ! (clearInterval(v_timerno), delete v_timerno)
Markus
SB 2.32 x86, Browser: Iron Portable V. 88.0.4500.0 (Chromium based), User age in 2023: 55y
"Happiness is a pet." | "Never run a changing system!"
"Happiness is a pet." | "Never run a changing system!"
Re: AddScreenTimer
HI
thanks for your time
maybe a safer workaround for now is to create a window with #PB_Window_Invisible
but in general this problem must addressed for future needs, i.e. create some global timers / screen timers etc
thanks for your time
maybe a safer workaround for now is to create a window with #PB_Window_Invisible
but in general this problem must addressed for future needs, i.e. create some global timers / screen timers etc
Christos
Re: AddScreenTimer
How about this?
Code: Select all
Procedure AddTimer(Timeout, Callback)
! return setInterval(v_callback, v_timeout);
EndProcedure
Procedure RemoveTimer(Timer)
! clearInterval(v_timer);
EndProcedure
Procedure TimerEvent()
Debug ElapsedMilliseconds()
EndProcedure
myTimer = AddTimer(1000, @TimerEvent())
; RemoveTimer(myTimer)
Re: AddScreenTimer
guys thanks for your time
both your codes prove that it is possible
However keep in mind that is posted in "Feature Request and Wishlist" section, and for reason explained i believe these commands should supported natively !
both your codes prove that it is possible
However keep in mind that is posted in "Feature Request and Wishlist" section, and for reason explained i believe these commands should supported natively !
Christos