ZFGC
Resources => Coding => Topic started by: ali on April 12, 2008, 05:23:38 am
-
How do I make a countdown? And when it hits 00:00:00 (min/sec/milisec) it ends the game?
Also display the countdown in text on the screen?
-
You know what Im not too sure. Lemme go check.
-
create an object
put an alarm event inside the object that increases the variable
then do all that division to get min, sec ,millisec
then put a draw event inside the object and use draw_text to draw it
-
Actually, that would make a countup... or a timer. Instead, decrease the variable from a certain value.
-
Actually, that would make a countup... or a timer. Instead, decrease the variable from a certain value.
erm, not really---
While the alarm counts steps, it's only counting steps to figure out when the alarm's event should execute. You do just about anything in the alarm's event, including subtract values...
For example
Alarm[0]'s event could be
Sec =- 1
and it would subtract Sec whenever Alarm[0] counts to 1000 milliseconds
-
Uh anybody got some code? 8)
-
Using alarms or decreasing a variable each step wouldn't actually be a proper countdown, since drops in the framerate would affect it. You can use variables like current_time to have a more accurate counter. Remember current_time is in milliseconds.
Start the timer (so create event or whatever)
maxtime = 30000 //30 seconds on the clock
start = current_time
Draw event
//Draw time remaining in minutes:seconds:milliseconds
draw_text(10,10,
string( floor( (start+maxtime-current_time) / 60000 ) ) //Minutes
+":"+
string( floor( ((start+maxtime-current_time) / 1000 ) mod 60 ) ) //seconds
+":"+
string( floor( (start+maxtime-current_time) mod 1000) ) //milliseconds
)
if (start+maxtime<current_time) game_end(); //When the timer reaches 0.
"mod" is to find the remainder of a division. If we mod the number of seconds by 60, we'll remove the "whole minutes" from it (otherwise 2 minutes would be displayed as 120 seconds, etc)
You could actually combine the start and maxtime variables, just thought it would be clearer like that.
-
This is easy!
create a countdown object and in the step event.
Initialize these vars, cur_time, min, sec;
var cur_time, min, sec, mili;
//Countdown code
cur_time = 10 //This is ten minutes not 10 seconds
cur_time = - min;
cur_time = +sec;
sec += 1;
if sec > 60 { min = -1
sec = 0;
};
now use the draw_text(x,y,string) function, the string can be anything but for this just use cur_time;
Hope that helps, never tested it though.
-
Works perfectly! Thanks a lot (http://www.zfgc.com/forum/Smileys/takam/cheesy.gif)
-
I didn't want to make another topic and flood this board so:
in the command obj_delete(ind) what is ind? It says it is the index but how do I know what object holds that index or you know yeah
obj_delete(ind)
Help please I need this now!
-
The name of the object is a constant which is equal to its index :P. Also there is object_index, which is the object index of the current instance.
BTW, obj_delete will delete completely the object so that you cannot create more instances of it and all its current instances will be destroyed. If you only want to destroy the actual instance, you can use instance_destroy();
-
The name of the object is a constant which is equal to its index :P. Also there is object_index, which is the object index of the current instance.
BTW, obj_delete will delete completely the object so that you cannot create more instances of it and all its current instances will be destroyed. If you only want to destroy the actual instance, you can use instance_destroy();
yeah someone at gmc told me