views:

52

answers:

2

Hi. I have a function in my game that you only can use every 2 min. So I have this code

$next = strtotime ("+2 minutes");

This function to check if 2 minutes has passed:

if(time() <= $next){

Here I find the time when you can do the function again:

date( "00:i:s", $next - time())

What I need is the number of seconds until you can launch the function. I use this javascript to countdown:

$wait = $next - time();

<form name="counter"><input type="text" size="8" name="d2"></form> 

<script> 
 var milisec=0 
 var seconds={$wait} 
 document.counter.d2.value='{$wait}' 

function display(){ 
 if (milisec<=0){ 
    milisec=9 
    seconds-=1 
 } 
 if (seconds<=-1){ 
    milisec=0 
    seconds+=1 
 } 
 else 
    milisec-=1 
    document.counter.d2.value=seconds+"."+milisec 
    setTimeout("display()",100) 
} 

display() 

Does $next - time() represent the correct number of seconds? It doesn't seem to be correct and that is a little important..

A: 

Isn't it simpler to do $next=time()+120?

Bick
Heh one reason why they used `strtotime()` is to avoid errors, like in your example, since you should have used 120 instead 12000, because `time()` returns the current time measured in the number of seconds since the Unix Epoch, and you assumed it's milliseconds, and even then it should be 2*60*1000 = 120000.
ArtBIT
Sorry, sorry) js-style )
Bick
A: 

If was caching the $wait variable causing the time to show up wrong. fixed..

ganjan