Hello,
I created a command to start a countdown.
I can't count in minutes and seconds, I only have seconds.
Is it possible to display in minutes and seconds?
My code :
CASE "!5": openGlobalButton( "countdown_button",78,60,42,20,13,300,16,"^3Race starts in %cpt% seconds"); BREAK;
As you can see, i put 300 for 300sec = 5 min, but it doesn't work.
Then you need to create an event called "race_start_timer".
In that event you lower $race_start_time_sec by one.
Then you need to calculated the minutes and minutes again, update the button and call the same event again.
Am doing this just from my head, so the code isn't tested.
From your questions, I can see that you don't understand the basics of programming and simple math.
I can not give you the finished working code, but I can steer you in the right direction. Read again this part that Yisc wrote above:
Then you need to create an event called "race_start_timer".
In that event you lower $race_start_time_sec by one.
Then you need to calculate the seconds and minutes again, update the button and call the same event again.
Your counter does not start because you didn't make one. You only display a message with initial settings, nothing is going on there, how do you expect a number to increment? It's not magic. I'm not trying to be rude, just pushing you a bit to think with your own head rather than asking for a finished solution to copy paste.
In order to create a countdown timer, you have to make a timer of some sort, a function that can read system time, I don't know how this is done in PHP.
Then you can make an event or a function that gets called when each second passes and increment your time variable. After that, you show your button with the message. After a certain preset time has passed you should no longer call the timer function.
That's perfectly fine, everyone starts from somewhere. Until you have some more meaningful question that shows you did some homework or at least googled it first before posting here, it's gonna be like this.
First, the question is not about PHP but about Lapper.
I wrote my code between PHP-tags to present them properly on this forum, that's all/
Second, if you are not helping but only trying to wind someone up or even worse, make them drop their question and efforts because of not getting answers, you are not helping and it would be better not to answer.
I find this and i adapt for lapper, i try tonight.
CASE "!5": // Durée du compte à rebours en secondes (5 minutes) $duration = 5 * 60;
// Date et heure de fin du compte à rebours $_SESSION['countdown_end_time'] = time() + $duration; $remaining_seconds = $duration;
// Conversion des secondes en minutes et secondes $minutes = floor($remaining_seconds / 60); $seconds = $remaining_seconds % 60;
// Affichage du compte à rebours openGlobalButton( "countdown_button",78,60,42,20,13,300,16, "^3Race starts in : $minutes minutes, $seconds secondes"); } BREAK;
Let us know if you got it to work, as it might help others at some point as well.
*edit*
I see that the code uses PHP functions which are not in Lapper.
So I think this won't work.
I will try to write the code as soon as I get home (in about 1,5 hour from now) and then post it here.
I believe you have made a few mistakes. You are setting the variable $remaining_seconds to a fixed value which is 5*60 and then using that same variable that will stay fixed to calculate minutes and seconds. I hope you see what is the issue there. It's better to do something like this:
before a case 5 is called, make a new variable $time0 = time(), then do
$_SESSION['countdown_end_time'] = time() - $time0
$remaining_seconds = $duration - $_SESSION['countdown_end_time']
The math you used for seconds and minutes will result in a message that shows minutes=5, seconds=5. You have to calculate like this:
$minutes = $remaining_seconds % 60
$seconds = $remaining_seconds;
I think this should be it, assuming function time() returns the system time in seconds.
// Durée du compte à rebours en secondes (5 minutes) $duration = 5 * 60;
// Date et heure de fin du compte à rebours $time0 = time(); $_SESSION['countdown_end_time'] = time() - $duration; $remaining_seconds = $duration-$_SESSION['countdown_end_time'];
// Conversion des secondes en minutes et secondes $minutes = $remaining_seconds % 60; $seconds = $remaining_seconds;
// Affichage du compte à rebours openGlobalButton( "countdown_button",78,60,42,20,13,300,16, "^3Race starts in : $minutes minutes, $seconds secondes");
BREAK;
Maybe it works and it's my line here that's wrong:
The code you found uses PHP functions (time, $_SESSION) that are not available in Lapper, so this will never work.
I will write the code when I get home, which is about half an hour from now.
IF ( $Seconds < 0 ) THEN # when seconds are negative $Minutes = $Minutes-1; $Seconds = 60 + $Seconds; ENDIF
$DisplaySeconds=$Seconds;
Timer( $KeyFlags );#Goto Countdowntimer EndSub
Then the actual button to display the time:
Sub Timer( $KeyFlags ) ### Display button ### openGlobalButton( "countdown_button",78,60,82,20,13,-1,16,"^3Race starts in " . $Minutes . " minutes and " . $DisplaySeconds . " seconds" ); ### End ###
### Reduce seconds by 1 ### ### If seconds are below 0, reduce minutes by 1 and set seconds back to 59 ### ### If seconds are below 10, add a leading 0 to the displayed value #### $Seconds = $Seconds-1;
IF ( $Seconds < 0 ) THEN $Minutes = $Minutes-1; $Seconds = 59; ENDIF
IF ( $Seconds < 10 ) THEN $DisplaySeconds="0".$Seconds; ELSE $DisplaySeconds=$Seconds; ENDIF ### End ###
### If minutes and seconds are greater then or equal to 0, use the 1 second loop, else close button ### IF ( $Minutes >= 0 && $Seconds >=0 ) THEN HostDelayedCommand( 1, Timer ); ELSE closeGlobalButton( "countdown_button" ); ENDIF ### End ### EndSub