How replace Delay()

Just starting out? Need help? Post your questions and find answers here.
munfraid
Posts: 104
Joined: Sat Mar 24, 2018 1:33 pm

How replace Delay()

Post by munfraid »

Hello everybody, this is maybe a true beginners question. In PB I could easily have blinking text using Delay().

Code: Select all

OpenWindow(0,0,0,600,400,"Test", #PB_Window_ScreenCentered)

TextGadget(0, 10, 10, 580, 40, "This is a text")

SetGadgetText(0, "")
Delay(200)
SetGadgetText(0, "This is a test")
Delay(200)
SetGadgetText(0, "")
Delay(200)
SetGadgetText(0, "This is a test")
Delay(200)
SetGadgetText(0, "")
Delay(200)
SetGadgetText(0, "This is a test")
How this can be achieved in SB?
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: How replace Delay()

Post by Peter »

There is no Delay() in JavaScript. Use AddWindowTimer() instead.

Code: Select all

#Window = 0
#TextGadget = 0
#Timer = 0

Procedure TimerEvent()
  
  If GetGadgetText(#TextGadget)=""
    SetGadgetText(#TextGadget, "This is a text")
  Else
    SetGadgetText(#TextGadget, "")
  EndIf
  
EndProcedure

OpenWindow(#Window, 0, 0, 300, 260, "Timer example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

TextGadget(#TextGadget, 10, 10, 280, 30, "This is a text")

AddWindowTimer(#Window, #Timer, 1000)

BindEvent(#PB_Event_Timer, @TimerEvent())
Greetings ... Peter
munfraid
Posts: 104
Joined: Sat Mar 24, 2018 1:33 pm

Re: How replace Delay()

Post by munfraid »

Ah, I see.. I think I understood this now. Thanks a lot, Peter! :D
Post Reply