Can anyone tell me why the “timer” (witch is a timer property on the object i have the script on) is pausing as soon as it is doing the “goo” calculation?
from GameLogic import *
cont = GameLogic.getCurrentController()
own = cont.owner
ext = own["Text"]
print ext
if ext == "goo":
x = 1
while x < 20000:
print x , "<><"
x+=1
print own["timer"]
own["Text"] = "Fisherman!!!"
Because all the script is run before the ge start to render the next frame…
The timer goes with the frames, and if a script slows the frames the timer slows too…
if not hasattr(bge,"counter"):
bge.counter=0 #the first time the script is run, it creates the global variable
...
...
here your code
...
...
bge.counter+=1
them, when your calculation is finished, you have in bge.counter the number of frames required to do it
time= bge.counter/bge.logic.getAverageFrameRate()
note:
if your code was
for i in range[0,x]
the code to put in the script is without the for, and using bge.counter instead of i (because each time the script is run, it increase by 1)
Connect your script to an always actuator, set fire true pulses on, and set the delay to 1, so each frame your script is run
As far as i read, the timer goes with the fps… Actually it works like a real timer, measuring the seconds, but maybe it does a strange approximation(maybe using the fram/fps to set the right time).
And always afaik, is better not to use the time.spleep() becouse it freezes all the ge… i used once the time module to get the current data. Maybe if you create a global var with the current time and the start, and subtract the current time at the end, you should have the exact time in seconds, and the unix time is really helpfull in this case.(but the ge timer goes with milliseconds, so is more precise, i think)
The game engine pauses until your while loop is done. So your timer will be paused for the amount of time it takes to print “><>” 20000 times, and the timer should be based on time according to the physics engine (iirc)