Doubt with the simpleUpdate

Good night.
I have a doubt with the simpleUpdate, I need to do is control the # of times the simpleUpdate calls a function , what happens is that I am taking the time of the system to make the call to the function every 5s but that call occurs between 290 to 350 times but I just need to call 1 time.

public void simpleUpdate(float tpf)
seconds = calendario.get(Calendar.SECOND);
text.setText(seconds+" -----"+(seconds%5));

    if((seconds %5) == 0)
        temperature= Vac.changeTemperature(Actualtemperature);
        textString.setText("No change");

In changeTemperature the temperature change by a random, what I need is that this change occurs only 1 time.

tpf means “time per frame”. And if you want to control how many times the update() is called you do something substantially wrong. Read our tutorials, they explain how you can move stuff etc. without tying to a fixed framerate.

accumulate the tpf each frame and then when its greater than or equal 5 then call ur function and set the timer to 0

If accuracy is important subtract 5s not set equal to 0…otherwise it will drift quite fast.

…although if accuracy is critical you might need to go to other approaches anyway.

I’m confused… do you want to call it just one time or one time every 5 seconds?

The issue with your code is that it will be (seconds % 5 == 0) for a full second. update() could be called lots of times during that one second. Probably better to just accumulate tpf in a counter and check for seconds > 5 and then clear the counter.

I’m assuming you don’t need real accuracy or a) this is entirely the wrong approach anyway, and b) if this is what’s tripping you up then hard-accuracy may be too complicated.

pspeed i want to call one time every 5 seconds…
now i’m searching how to use and accumulate the tpf
thanks for your help…

That’s easy, you just need a float field (for example localTime) :
localTime += tpf;
if (tpf > 5) {
//Do whatever you want
localTime -= 5;

this is one solution that i found and it works…
long currTime = System.currentTimeMillis();
if(prevUpdate != -1)
updateTimeElapsed += (int)(tpf * 1000f);
systemTimeElapsed += (currTime - prevUpdate);
prevUpdate = currTime;
if(systemTimeElapsed % 500 == 0)
//textString.setText(“sys=” + systemTimeElapsed + “, update=” + updateTimeElapsed);
temperature = Vac.changeTemperature(ActualTemperature);

thanks for your help…