Page 1 of 1

Debug output failing?

Posted: Thu Apr 11, 2024 3:41 pm
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

Re: Debug output failing?

Posted: Thu Apr 11, 2024 7:53 pm
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())


Re: Debug output failing?

Posted: Fri Apr 12, 2024 2:47 am
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.

Re: Debug output failing?

Posted: Sat Apr 13, 2024 10:50 am
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

Re: Debug output failing?

Posted: Sun Apr 14, 2024 6:03 pm
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.