Debug output failing?

Just starting out? Need help? Post your questions and find answers here.
jphoarau
Posts: 22
Joined: Thu Dec 28, 2023 4:30 am

Debug output failing?

Post by jphoarau »

In the small piece of code below, the Debug is only displayed at the end of the execution whereas it should be displayed every second. Does anyone know why?
Thanks in advance.

Code: Select all

Procedure Wait(milliseconds)
  Start = ElapsedMilliseconds()
  
  Repeat
    delay = (ElapsedMilliseconds()-Start)
  Until (delay > milliseconds)
  
EndProcedure

For x = 1 To 5
  Debug Str(x); Only displayed at the end of 5 iterations... Why? (While it works very well in Purebasic)
  Wait(1000)
Next x
munfraid
Posts: 135
Joined: Sat Mar 24, 2018 1:33 pm

Re: Debug output failing?

Post by munfraid »

SB creates javascript, which runs asynchronously.
Things like Delay() won't work.

In SB use timers instead.

Code: Select all

Procedure TimerEvents()
  
  Static a
  a+1
  Debug a  
  
EndProcedure

OpenWindow(0, 0, 0, 0, 0, "Timer", #PB_Window_Background)
AddWindowTimer(0, 0, 1000)
BindEvent(#PB_Event_Timer, @TimerEvents())

jphoarau
Posts: 22
Joined: Thu Dec 28, 2023 4:30 am

Re: Debug output failing?

Post by jphoarau »

munfraid wrote: Thu Apr 11, 2024 7:53 pm In SB use timers instead.
Okay, but in this case, how to make a Timer that only executes once to have the equivalent of Wait(1000) for example? There is RemoveWindowTimer(#Window, Timer), but how to be sure that the next Timer will not be executed before the first one is terminated.Thanks.
munfraid
Posts: 135
Joined: Sat Mar 24, 2018 1:33 pm

Re: Debug output failing?

Post by munfraid »

I'm not sure if I understood right what you are looking for.
Maybe this post can help you:
https://forums.spiderbasic.com/viewtopic.php?p=7915#p7915
jphoarau
Posts: 22
Joined: Thu Dec 28, 2023 4:30 am

Re: Debug output failing?

Post by jphoarau »

Thank you munfraid. It gives me an idea. But this is incredible to write such many lines of code for a single timer... In PB it is more simple.
Post Reply