in time, ElapsedMilliseconds() gave a number other than 0 when running a code. Now watch:
Code: Select all
Delay(100)
Debug ElapsedMilliseconds()
Delay(100)
Debug ElapsedMilliseconds()
Code: Select all
Delay(100)
Debug ElapsedMilliseconds()
Delay(100)
Debug ElapsedMilliseconds()
Code: Select all
ElapsedMilliseconds()
Delay(100)
Debug ElapsedMilliseconds()
Delay(100)
Debug ElapsedMilliseconds()
It was changed a few versions back. The Manual gives a hint that ElapsedMilliseconds() is not for the actual time but for timing the 'time between calls' also know as the elapsed milliseconds .
Oops! I didn't know that and it breaks some of my logic. I assumed it was elapsed milliseconds since the program started. I've now added this macro:
Code: Select all
Macro myMilliseconds()
(qMyElapsedMilliseconds + ElapsedMilliseconds())
EndMacro
Code: Select all
Debug "GetTickCount_()" ; == sample output
Debug GetTickCount_() ; == 672279453
Delay(500) ;
Debug GetTickCount_() ; == 672279953
Debug "ElapsedMilliseconds()" ;
Debug ElapsedMilliseconds() ; == 0
Delay(500) ;
Debug ElapsedMilliseconds() ; == 500
Code: Select all
While on
If nonFirstLoop = 0
nonFirstLoop = 1
tIni = ElapsedMilliseconds()
EndIf
t1 = ElapsedMilliseconds() - tIni
dt21 = t1 - t2
mainLoopOps()
t2 = ElapsedMilliseconds() - tIni
dt12 = t2 - t1
If dt12 < msPerLoop ; without tIni, the first loop has no delay because this safety condition "thinks" the previous delay (which really does not exist) would be very VERY long...
Delay(msPerLoop - dt12)
EndIf
Wend
Code: Select all
While on
t1 = ElapsedMilliseconds()
dt21 = t1 - t2
mainLoopOps()
t2 = ElapsedMilliseconds()
dt12 = t2 - t1
If dt12 < msPerLoop
Delay(msPerLoop - dt12)
EndIf
Wend
Code: Select all
While on
t1=ElapsedMilliseconds()+msPerLoop
mainLoopOps()
If ElapsedMilliseconds()<t1
Delay(t1-ElapsedMilliseconds())
EndIf
Wend
You don't have to set a random seed by yourself because Purebasic automatically ensures that the seed is different on every program start. You only need RandomSeed() if you really want to set it to a specific value.