The Daily Click ::. Forums ::. Klik Coding Help ::. How do you make a custom timer?
 

Post Reply  Post Oekaki 
 

Posted By Message

JetpackLover



Registered
  01/03/2007
Points
  212
20th June, 2009 at 18:35:21 -

One that looks like this 00:00:00 minutes/seconds/milliseconds

and how would I make it count up?

I honestly have no clue...please help

 
http://www.invincibletime.com/

Devlog for HD MMF Game Omulus. Check it out because it's gonna be awesome. http://omulus.tumblr.com/

Follow me on the twitters https://twitter.com/JetpackLover


Muz



Registered
  14/02/2002
Points
  6499

VIP MemberI'm on a BoatI am an April FoolHonored Admin Alumnus
20th June, 2009 at 18:42:17 -

Create counter 1, counter 2, counter 3.
Counter 1 = minutes
Counter 2 = seconds

Every 1 second,
add 1 to counter 2.
When counter 2 = 60,
set counter 2 to 0
add 1 to counter 1.


Milliseconds are going to be a problem, though. I think MMF can only go as low as 0.02 seconds, and not accurately.

 
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.

Image

JetpackLover



Registered
  01/03/2007
Points
  212
20th June, 2009 at 18:58:10 -

I'm not really a fan of using the built in timer movement

What I'm using now is Always> add 1 to counter

I was told by someone that there is a way to use counters and have them work like timers based on division or something. I can't remember how that is done though.

It was something like 1/100 equals minutes 1/1000 equals hours, something like that don't quote me on it though

Anyone know what I'm talking about?

Also I supposed it doesn't really matter if the milliseconds aren't dead on, but why can't MMF count them accurately?

 
http://www.invincibletime.com/

Devlog for HD MMF Game Omulus. Check it out because it's gonna be awesome. http://omulus.tumblr.com/

Follow me on the twitters https://twitter.com/JetpackLover


Silveraura

God's God

Registered
  08/08/2002
Points
  6747

Game of the Week WinnerKlikCast StarAlien In Training!VIP Member360 OwnerWii OwnerSonic SpeedThe Cake is a LieComputerChristmas Tree!
I am an April Fool
20th June, 2009 at 19:06:31 -

It's designed to stay in sync with actual time, not it's own internal loop. That's why you need to make your own loop, which you really should be doing anyway.

 
http://www.facebook.com/truediamondgame

JetpackLover



Registered
  01/03/2007
Points
  212
20th June, 2009 at 19:07:29 -

Forgive me if I sound dumb but what do you mean?

 
http://www.invincibletime.com/

Devlog for HD MMF Game Omulus. Check it out because it's gonna be awesome. http://omulus.tumblr.com/

Follow me on the twitters https://twitter.com/JetpackLover


OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
20th June, 2009 at 19:20:15 -

MMF runs by loops, it goes through the conditions then does it again, and then again. I think it's once per .02 seconds or something. So if you added 1 to a counter every loop, it would be a funky number depending on the speed. (FPS, more or less)

If you use Always, that's what it will do. The timer is separate from the loops... I think.

Edited by OMC

 

  		
  		

JetpackLover



Registered
  01/03/2007
Points
  212
20th June, 2009 at 19:38:54 -

So has anyone made an accurate timer?

 
http://www.invincibletime.com/

Devlog for HD MMF Game Omulus. Check it out because it's gonna be awesome. http://omulus.tumblr.com/

Follow me on the twitters https://twitter.com/JetpackLover


Spitznagl

Cabinetmaker

Registered
  06/12/2008
Points
  4260

The SpinsterVIP MemberHas Donated, Thank You!Picture Me This Round 29 Winner!Picture Me This Round 31 Winner!Picture Me This Round 36 Winner!
20th June, 2009 at 21:28:38 -


Originally Posted by DudeHuge
I was told by someone that there is a way to use counters and have them work like timers based on division or something. I can't remember how that is done though.

It was something like 1/100 equals minutes 1/1000 equals hours, something like that don't quote me on it though
Anyone know what I'm talking about?



He was probably using the modulus operator. This way, you only need one value.
Here's a simple example:
http://www.mediafire.com/download.php?gnitnhnyznm

It seems to lose not even half a second every hour, and my watch could too fast.

 
...

Hernan



Registered
  04/03/2003
Points
  707

VIP Member
20th June, 2009 at 21:42:25 -

If you have a counter that counts the milliseconds then:
milliseconds=counter mod 1000
seconds=(counter/1000) mod 60
minutes=(counter/60000) mod 60
hours=(counter/3600000) mod 24 (you don't need the mod 24, if you're not counting days)
etc.

 
This space is for rent

Spitznagl

Cabinetmaker

Registered
  06/12/2008
Points
  4260

The SpinsterVIP MemberHas Donated, Thank You!Picture Me This Round 29 Winner!Picture Me This Round 31 Winner!Picture Me This Round 36 Winner!
20th June, 2009 at 22:09:55 -

For the seconds and higher, don't you also need to substract the lower value before you divide?
That or you put the formulas between int() to get rid of the decimals.

 
...

Hernan



Registered
  04/03/2003
Points
  707

VIP Member
20th June, 2009 at 22:50:01 -

By default, MMF works in integers. So there's no need for placing int().
I'm not sure what you mean by "lower value" though.

Edit: I took a look at your example, and I see what you mean with "lower value" now. The answer is no, I do a different calculation than what you do. I calculate the total amount of seconds (by dividing the total milliseconds by 1000) and then remove the counts higher than 60 by taking mod 60.
What you do is different (it's all correct though, but seems much more complicated to me), you actually first get rid of all the minutes by taking mod 60000, then you get rid of the milliseconds by subtracting the mod 1000 and then finally divide by 1000 to convert the milliseconds to seconds. (actually you were working in centiseconds, but that all works the same)
You follow me?

Edit again: Sקɪтzпαɢʟ, I just realised that you are making things too hard for yourself Like I said, you actually subtract the milliseconds, but you don't need to do that! Dividing by 1000 is enough, because as I said earlier MMF works in integers by default. You don't need to get rid of the "lower value" at all! So if you remove the "-Global Value A mod 6000" part everywhere, you'll see that your timer will still work

Edited by Hernan

 
This space is for rent

Spitznagl

Cabinetmaker

Registered
  06/12/2008
Points
  4260

The SpinsterVIP MemberHas Donated, Thank You!Picture Me This Round 29 Winner!Picture Me This Round 31 Winner!Picture Me This Round 36 Winner!
20th June, 2009 at 23:38:34 -

You are right! Thanks

 
...

Muz



Registered
  14/02/2002
Points
  6499

VIP MemberI'm on a BoatI am an April FoolHonored Admin Alumnus
21st June, 2009 at 02:08:55 -

Yeah, it's designed to run at the frame rate. One loop is run every 1/FrameRate seconds. So, if you have 50 FPS (default), it's 0.02 seconds per loop. You can't count faster than that without some sort of extension for it. And if your FPS drops, the built-in timer might skip over the 0.02 second count.

So, you can't count in milliseconds. You should be using a 'timer counter' like that for all your timer events anyway. I was thinking of writing an article about that some time but never got to it

 
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.

Image

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
21st June, 2009 at 03:22:25 -

use my widget.

http://supertacogames.com/index.php?page=Download%20Details&id=8

this question has been asked quite a bit lately. hmmm.

Edited by Cecilectomy

 
n/a

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
21st June, 2009 at 09:23:36 -

Use the TimeX extension? I'm pretty sure that's independent of MMF's loops, but someone should verify that.

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
21st June, 2009 at 09:33:21 -

my widget uses timeX object. im pretty sure its mmf independant. its as accurate as your computers clock.

 
n/a

Silveraura

God's God

Registered
  08/08/2002
Points
  6747

Game of the Week WinnerKlikCast StarAlien In Training!VIP Member360 OwnerWii OwnerSonic SpeedThe Cake is a LieComputerChristmas Tree!
I am an April Fool
21st June, 2009 at 09:35:45 -

The whole point of designing your own internal timer is to avoid being in sync with the computer clock. If you want to be in sync with the computer clock, just use the timer options in MMF2 itself. However if you're trying to create a game that depends on it's own internal values to keep track of everything, that's when you need an internal loop of your own.

 
http://www.facebook.com/truediamondgame

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
21st June, 2009 at 09:41:34 -

brandon who said anything about being synced with the computers clock? when you start a timeX objects clock it keeps accurate time in milliseconds until you stop it. it still follows the rules of pausing when the app is minimized, being moved, or resized, unless you specify in the application settings. if you base it completely internally its going to end up being inaccurate to some degree. defeating the purpose of a clock in the first place.

 
n/a

JetpackLover



Registered
  01/03/2007
Points
  212
21st June, 2009 at 19:25:53 -


Originally Posted by Hernan
If you have a counter that counts the milliseconds then:
milliseconds=counter mod 1000
seconds=(counter/1000) mod 60
minutes=(counter/60000) mod 60
hours=(counter/3600000) mod 24 (you don't need the mod 24, if you're not counting days)
etc.



Hernan can I get an example of how this would work in MMF?(doesn't have to be an MFA.)

 
http://www.invincibletime.com/

Devlog for HD MMF Game Omulus. Check it out because it's gonna be awesome. http://omulus.tumblr.com/

Follow me on the twitters https://twitter.com/JetpackLover


Hernan



Registered
  04/03/2003
Points
  707

VIP Member
21st June, 2009 at 23:16:59 -


Originally Posted by DudeHuge

Originally Posted by Hernan
If you have a counter that counts the milliseconds then:
milliseconds=counter mod 1000
seconds=(counter/1000) mod 60
minutes=(counter/60000) mod 60
hours=(counter/3600000) mod 24 (you don't need the mod 24, if you're not counting days)
etc.



Hernan can I get an example of how this would work in MMF?(doesn't have to be an MFA.)



Do I need to? It's dead easy ._. You only need to create 1 event!
Create 4 counters, let's call them 'counter', 'milliseconds', 'seconds', 'minutes'

Always
-Add 20 to 'counter'
(Yes I know, it won't be synced to real time etc etc. But let's assume DudeHuge doesn't need/want real time and has his game on 50fps)
-Set 'milliseconds' to value("counter") mod 1000
-Set 'seconds' to (value("counter")/1000) mod 60
-Set 'minutes' to (value("counter")/60000)

Alternatively, you can replace -Add 20 to 'counter' with -Set 'counter' to timer
if you do want it to be synced with real time.

 
This space is for rent

JetpackLover



Registered
  01/03/2007
Points
  212
22nd June, 2009 at 02:02:07 -

I've decided to use the widget it works brilliantly for what I want it for. Thanks for the enlightenment on all this stuff guys I appreciate it.

 
http://www.invincibletime.com/

Devlog for HD MMF Game Omulus. Check it out because it's gonna be awesome. http://omulus.tumblr.com/

Follow me on the twitters https://twitter.com/JetpackLover


Silveraura

God's God

Registered
  08/08/2002
Points
  6747

Game of the Week WinnerKlikCast StarAlien In Training!VIP Member360 OwnerWii OwnerSonic SpeedThe Cake is a LieComputerChristmas Tree!
I am an April Fool
22nd June, 2009 at 06:04:47 -


Originally Posted by rand(0, $Cecil);
brandon who said anything about being synced with the computers clock? when you start a timeX objects clock it keeps accurate time in milliseconds until you stop it. it still follows the rules of pausing when the app is minimized, being moved, or resized, unless you specify in the application settings. if you base it completely internally its going to end up being inaccurate to some degree. defeating the purpose of a clock in the first place.



When people say miliseconds or seconds, at least to me, it's automatically assumed that they're talking about accurate time, not internal game time. I mean if you you're talking about 1 second internal to the game, 1 second is going to be twice as long at 30fps then it is at 60fps, which could be both undesirable to some people and highly desirable to others. Few people ever consider this, which is the entire reason why I was trying to put it out there.

 
http://www.facebook.com/truediamondgame

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
22nd June, 2009 at 07:06:02 -

i see but its also desirable to have things in the game run at the same speed regardless of framerate. time based movements. thats why in most games when the frame rate drops you still move just as fast, just in fewer frames updated at longer intervals. i see where that can cause problems in mmf. i dont think the built in movements are timer based are they? and most custom movements dont use a time delta for movement.

i may update my widget to flag whether or not to use internal time based on framerate, or accurate external time. thanks brandon.

 
n/a

Silveraura

God's God

Registered
  08/08/2002
Points
  6747

Game of the Week WinnerKlikCast StarAlien In Training!VIP Member360 OwnerWii OwnerSonic SpeedThe Cake is a LieComputerChristmas Tree!
I am an April Fool
22nd June, 2009 at 08:25:34 -


Originally Posted by rand(0, $Cecil);
i see but its also desirable to have things in the game run at the same speed regardless of framerate. time based movements. thats why in most games when the frame rate drops you still move just as fast, just in fewer frames updated at longer intervals. i see where that can cause problems in mmf. i dont think the built in movements are timer based are they? and most custom movements dont use a time delta for movement.

i may update my widget to flag whether or not to use internal time based on framerate, or accurate external time. thanks brandon.



Actually, they achieve that by skipping frames, not by using external loops. It's actually highly undesirable to use external loops for in-game actions, especially movement based. If your game suddenly dips in framerate, you'll start getting a lot of varied results. For example, if you have a player that falls 1 pixel every 0.1 seconds and your game suddenly hitches up for a few seconds, he's going to be short cut his jump and that's going to cause a lot of frustration for the player. It's best to use internal loops and just turn on machine independent speed. That way your game still relies on it's internal loops, but skips rendering frames so as to keep the game from being slowed down by it's ability to render.

 
http://www.facebook.com/truediamondgame

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
22nd June, 2009 at 08:46:09 -

what? external loops?

not when its based on difference in time. delta.

mmf loops 50 times a second. it it sudennly increases to 100 the total distance moved will be exactly the same. it will move according to the difference.

read this. im not sure im communicating what im actually thinking of well or you arent reading it well. this is what im talking about.

http://ruby.about.com/od/gameprogramming/ss/gameprog4_5.htm

 
n/a
   

Post Reply



 



Advertisement

Worth A Click