AddScreenTimer

Got an idea for enhancing SpiderBasic? New command(s) you'd like to see?
plouf
Posts: 97
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

AddScreenTimer

Post by plouf »

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
Christos
User avatar
Kurzer
Posts: 85
Joined: Mon May 26, 2014 9:33 am

Re: AddScreenTimer

Post by Kurzer »

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])}}

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)
Maybe this will help you as a workaround.

Markus
SB 2.32 x86, Browser: Iron Portable V. 88.0.4500.0 (Chromium based), User age: 53y
"Happiness is a pet." | "Never run a changing system!"
plouf
Posts: 97
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: AddScreenTimer

Post by plouf »

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
Christos
User avatar
Peter
Posts: 888
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: AddScreenTimer

Post by Peter »

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)
plouf
Posts: 97
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: AddScreenTimer

Post by plouf »

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 ! :)
Christos
Post Reply