ZFGC

Resources => Coding => Topic started by: ali on April 12, 2008, 05:23:38 am

Title: Gamemaker countdown
Post 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?
Title: Re: Gamemaker countdown
Post by: King Tetiro on April 12, 2008, 08:03:17 am
You know what Im not too sure. Lemme go check.
Title: Re: Gamemaker countdown
Post by: Windy on April 12, 2008, 08:22:25 am
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
Title: Re: Gamemaker countdown
Post by: Dumb_Ass on April 12, 2008, 08:26:20 am
Actually, that would make a countup... or a timer. Instead, decrease the variable from a certain value.
Title: Re: Gamemaker countdown
Post by: Mamoruanime on April 12, 2008, 08:48:03 am
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
Title: Re: Gamemaker countdown
Post by: ali on April 12, 2008, 05:51:39 pm
Uh anybody got some code? 8)
Title: Re: Gamemaker countdown
Post by: mit on April 12, 2008, 06:15:24 pm
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)
Code: [Select]
maxtime = 30000 //30 seconds on the clock
start = current_time

Draw event
Code: [Select]
//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.
Title: Re: Gamemaker countdown
Post by: Rukiri on April 12, 2008, 06:20:11 pm
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.
Title: Re: Gamemaker countdown
Post by: ali on April 12, 2008, 06:26:54 pm
Works perfectly! Thanks a lot (http://www.zfgc.com/forum/Smileys/takam/cheesy.gif)
Title: More Gamemaker Help
Post by: ali on April 13, 2008, 09:05:10 pm
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

Code: [Select]
obj_delete(ind)
Help please I need this now!
Title: Re: Gamemaker countdown
Post by: Darth RPG on April 13, 2008, 10:51:39 pm
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();
Title: Re: Gamemaker countdown
Post by: ali on April 13, 2008, 11:18:54 pm
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

Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved