MODULE: CountDown v1.1 - Countdowns simplified! - Updated 03 September 2010

Started by monkey0506, Thu 17/12/2009 00:48:09

Previous topic - Next topic

monkey0506

In response to this long-standing thread regarding a countdown timer, I've decided to go ahead and simplify the process by modularizing the code. With the countdown module you can easily create countdown timers up to 99 hours, 59 minutes, and 59 seconds (though this isn't a technical limitation, I just put it there for fun I guess).

You can also easily display the countdown on a label by formatting it such as:
H hours, M minutes, S seconds remaining...
Or any other format you might like. Maybe you prefer:
HH:MM:SS
instead? Well the format is highly customizable with 7 different tags that can be used, and aside from those you can put whatever text you like!

To take it a step further there are also some "TimesUp" events that are automatically triggered. Currently you can have a character announce that the time has run out (optionally using Display instead of Character.Say) and you can move the character to a new room (optionally specifying new co-ordinates). Once set up these events will automatically be fired off when the countdown runs out completely. I'd actually be interested to see if anybody else has ideas about other events you might like to see automatically triggered, so if you think of something let me know! :)

03 September 2010
Uploaded v1.1 with a bug fix for TimesUpText and TimesUpNewRoom which weren't working because they can't be called from repeatedly_execute_always. Thanks to Buckethead for noticing this bug..due to my own lack of testing. ;D

Download (Mirror)
View the manual online (Thanks RickJ for the Modox module!*)

Let me know what you think!

*Just to clarify this, I did use the Modox module v1.0, but I also highly modified/edited the output by hand. No offense to Rick, but the module is still in early stages, and I wanted to tweak things a bit.

Rocco

sorry, i dont want to hickjack your thread.  :-\
I also have a finished countdown module on the harddrive for a while (without documentation).
I planned to make a demo and documtation over the holydays and release it accordingly.
but im not sure now, cause it doesnt make much sense to have different modules with the same functionality.



monkey0506

Well I myself have done the same thing before...put off releasing code and then suddenly realized someone else had gone and done it already (as a matter of fact...I believe...yes, that was you :)). AFAIK the only module that currently exists in duplicate is the background speech modules (by SSH and myself). That came about because I'd already been working on modularizing the code and refused to be deterred just because SSH released his code first.

Other than that I have actually adopted the SlideRoom module (originally by strazer I believe) and the EncryptedFile module (originally by HeirOfNorton) but those aren't strictly duplicate modules, they're intended as updated versions. 8)

There wouldn't be any hard feelings if you wanted to release your own code. As you said if they're offering the "same functionality" then it doesn't make much sense (from a logistics standpoint) to have multiple modules, but if you wanted to offer something that my module presently doesn't then I wouldn't be upset if you just released your own code instead of telling me how to "fix" my module. :=

Anyway, that thread just recently got dragged back up because the code was still valid despite the thread being around 2 years old. That's why this module is compatible (presumably, I haven't actually tested this mind you) with all AGS version 2.71 and higher. Hopefully somebody will find it useful. :D

Rocco

lol, seems that this is some kind of poetic justice.  ;D

well, the difference between our modules is, that i have more of a short term timer, which uses
only minutes, seconds and hundreds without hours,
the other thing is that you can choose between count backwards or forward to a specific value.
this is the whole functionality, without comfortability as you provide with special functions like TimesUpText,
so the developer had to write something like
Code: ags

if(timer.over)
{ 
player.Say("OMG we'll die like rotten sheep!!");
timer.over = false;
// Explosion Code
}


here is a little demo:
http://www.virtual-illusion.com/rocco/Countdown-Timer_Demo.zip

monkey0506

By "hundreds" I presume you mean "1/100th of a second" but unless the game speed is set to at least 100 how can that be reliably updated? The default game speed is 40 (game loops/frames per second), so you would have to then go in increments of 2(.5) (2, 5, 7, 10, 12, 15, 17, 20, 22, 25, etc.). I guess you could do something such as:

Code: ags
float fhundredths = 0.0;
int ihundredths = 0;

fhundredths += (100.0 / IntToFloat(GetGameSpeed()));
if (fhundredths > 100.0) fhundredths -= 100.0;
ihundredths = FloatToInt(fhundredths, eRoundDown);


Of course the same thing could be accomplished in my module which does offer the ability to get the raw time remaining in actual game loops.

Okay, I've just taken a look and it seems that your hundreds place counts by exactly 2, you didn't mess around with the .5 bit. :) I'm a bit confused by your "Stop" and "Pause" buttons. It seems they do exactly the same thing.

My module doesn't have the ability to count up though, you're right about that. If someone wanted a stopwatch they could always do something like:

Code: ags
CountDown.SetTime(59, 59, 99); // seconds, minutes, hours
int h = 99 - CountDown.Hours;
int m = 59 - CountDown.Minutes;
int s = 59 - CountDown.Seconds;


If anybody is interested in that though I could easily add a Direction parameter and property.

:) Thanks for feedback.

Rocco

Yes, the way i calculate the hundredths is nearly as you suggested:
Code: ags

timer.hundreths = (100/GetGameSpeed()) * timer.frame_counter;  
timer.hundreths = 99 - timer.hundreths;


I guess, hundreths make a counter much more dramatic.  ;D

Stop and Pause are the same, the only difference is the flag, so the developer can different between a timer who is aborted or stopped.
Dont know if this makes much sense.

I developed this module to be used in my own game, but wasnt far enough with the game to implement and test the module within,
this is also the reason why i didnt release the module so far, cause i always try to test the modules in real game situations, to see if all works as supposed.

So, when you implement this things, i'll use yours.  :)




Buckethead

Cool it works now thanks! Sad that not more people have tested/used this module.

monkey0506

Heh, it was my fault for not properly testing my code to begin with. Or realizing that blocking functions in rep_ex_always won't work. :=

I just had to move a few lines around and add an exception so that the count down is updated in rep_ex_always wherever possible, but it only checks for the TimesUp events in the blockable rep_ex.

Pinback

Quote from: Buckethead on Fri 03/09/2010 17:58:06
Sad that not more people have tested/used this module.

I'm using it, great module by the way monkey, I haven't found any bugs so far and it's working a treat.
Had some difficulties displaying the time on a UI that appears and dissappears, but I solved it by having the time display move off screen when the UI isn't visible, and all is well.

monkey0506

Egads..I just realized I didn't update any of the module version information in the module itself, or include the new version macro. This is what happens when I apply 5 minute fixes under pressure from my roommate who is desperately trying to complete Curse of Monkey Island for the first time. :=

SMF spam blocked by CleanTalk