Page 1 of 3

real Time Clock - Am and PM, not militarry!

PostPosted: Fri Sep 11, 2009 3:53 am
by Hblade
Hi guys, I found a way to be able to read REAL TIME CLOCK, not militarry time. So in other words it wont be saying stuff like, 22:22, it'll say 11:22 PM :D Anyways, here's the code
Code: Select all
int Hour;
int Mode;
void DisplayTime()
{
    stTime u = getTime();
    if (Mode == 0)
    {
    sprintf(text, "%d:%d:%d AM", Hour, u.min, u.sec);
    }
    if (Mode == 1)
    {
        sprintf(text, "%d:%d:%d PM", Hour, u.min, u.sec);
    }
    if (u.hour<13)
    {
        Hour = u.hour;
    }
    if (u.hour>12)
    {
        Mode = 1;
    }
    if (u.hour<12)
    {
        Mode = 0;
    }
    if (u.hour == 12)
    {
        Mode = 1;
    }
    switch(u.hour)
    {
        case 13:
        Hour = 1;
        break;
        case 14:
        Hour = 2;
        break;
        case 15:
        Hour = 3;
        break;
        case 16:
        Hour = 4;
        break;
        case 17:
        Hour = 5;
        break;
        case 18:
        Hour = 6;
        break;
        case 19:
        Hour = 7;
        break;
        case 20:
        Hour = 8;
        break;
        case 21:
        Hour = 9;
        break;
        case 22:
        Hour = 10;
        break;
        case 23:
        Hour = 11;
        break;
        case 24:
        Hour = 12;
        break;
    }
}


=]How to use[=
In your text actor, click Add - Draw Actor - Script editor, then put this code in it
DisplayTime();
then click ok, and watch as it displays real time.
here's a screenshot
screenys.jpg



Hehe... I made a lil system clock.
Untitled.jpg


12:00 AM Fix:

I foudn out that uh... if it's 12:00 Am then it uh... sets it'sself to 0, but now I fixed that. here's the code
Code: Select all
int Hour;
int Mode;
void DisplayTime()
{
    stTime u = getTime();
    if (Mode == 0)
    {
    sprintf(text, "%d:%d:%d AM", Hour, u.min, u.sec);
    }
    if (Mode == 1)
    {
        sprintf(text, "%d:%d:%d PM", Hour, u.min, u.sec);
    }
    if (u.hour<13 && u.hour>0)
    {
        Hour = u.hour;
    }
    if (u.hour>12)
    {
        Mode = 1;
    }
    if (u.hour<12)
    {
        Mode = 0;
    }
    if (u.hour == 12)
    {
        Mode = 1;
    }
    if (u.hour == 0)
    {
        Hour = 12;
    }
    switch(u.hour)
    {
        case 13:
        Hour = 1;
        break;
        case 14:
        Hour = 2;
        break;
        case 15:
        Hour = 3;
        break;
        case 16:
        Hour = 4;
        break;
        case 17:
        Hour = 5;
        break;
        case 18:
        Hour = 6;
        break;
        case 19:
        Hour = 7;
        break;
        case 20:
        Hour = 8;
        break;
        case 21:
        Hour = 9;
        break;
        case 22:
        Hour = 10;
        break;
        case 23:
        Hour = 11;
        break;
        case 24:
        Hour = 12;
        break;
    }
}


Anyways, yeah now the clock is fixed :D

Enjoy

Re: real Time Clock - Am and PM, not militarry!

PostPosted: Fri Sep 11, 2009 11:48 am
by Chai
It's very good idea
I'm still thinking how to apply this to a game.
Good job.
Thank you very much for your contribution.

Re: real Time Clock - Am and PM, not militarry!

PostPosted: Fri Sep 11, 2009 2:22 pm
by Hblade
Thanks :D Anyway, to apply this in your game, simply make a text actor, then go to draw actor, then put DisplayTime();



In Global code you need to put the code up top before you can use DisplayTime();

Re: real Time Clock - Am and PM, not militarry!

PostPosted: Tue Sep 22, 2009 5:12 am
by NUTINC
I can see some uses for this in an economic game :twisted:

Re: real Time Clock - Am and PM, not militarry!

PostPosted: Fri Oct 02, 2009 6:01 pm
by BloodRaven
Nice mannn thanks , thanks a lot ......

Really i am looking for a code like this .....
I have created a CLOCK but it is little different becoz of the game.But i am trying to create a clock like a real clock.
I posted a small demo [my clock ] Can you help me in completing that clock to looks like a real clock ...
My clock is set on the HEALTH BAR ....
I am using lines to draw that " tics " ..... Its rotating but it is based on a PATH which is set by me...
I can complete that clock but only using PATHS.

Here is the method :
I created 2 actors [ hidden ]
I set their paths to rotate the base ....
and i set code to draw lines to follow each actor.So it moves....

The speed is adjusted in the path ; can you give any idea how to get the real values else any other method ????
Do you have any idea to create or get values of minutes ; seconds ; and hours separately ????

Re: real Time Clock - Am and PM, not militarry!

PostPosted: Sun Oct 04, 2009 6:10 pm
by Bee-Ant
FREAKIN LONG FOR A SUCH CODE...
Try this one :D
Code: Select all
stTime t=getTime();
sprintf(text,"%i:%i %s",t.hour%12,t.min,(t.hour<12)?"am":"pm");

Re: real Time Clock - Am and PM, not militarry!

PostPosted: Mon Oct 05, 2009 7:15 pm
by Kalladdolf
Yea, Bee-ant, that's what I'd have done lol.

Re: real Time Clock - Am and PM, not militarry!

PostPosted: Mon Oct 05, 2009 8:41 pm
by Bee-Ant
Whats your clue? :P

Re: real Time Clock - Am and PM, not militarry!

PostPosted: Tue Oct 06, 2009 1:59 pm
by Hblade
Mine looks more pro >.>

Re: real Time Clock - Am and PM, not militarry!

PostPosted: Tue Oct 06, 2009 4:44 pm
by MrJolteon
What's wrong with military clocks?

Re: real Time Clock - Am and PM, not militarry!

PostPosted: Tue Oct 06, 2009 5:03 pm
by Bee-Ant
Hblade wrote:Mine looks more pro >.>

From which point of view? :?
We're talking about eficiency... :P

@Jolty: Making real time clock doesnt mean hate the military one. We are just look for another variation.

Re: real Time Clock - Am and PM, not militarry!

PostPosted: Tue Oct 06, 2009 6:43 pm
by Kalladdolf
Bee-Ant wrote:
Hblade wrote:Mine looks more pro >.>

We're talking about eficiency... :P

Exactly.
Complicated ≠ Pro (not referring to pyro here).

Re: real Time Clock - Am and PM, not militarry!

PostPosted: Tue Oct 06, 2009 11:40 pm
by Bee-Ant
Kalladdolf wrote:(not referring to pyro here).

Looking his codes just make me headache. I wonder where's that boy now?

Re: real Time Clock - Am and PM, not militarry!

PostPosted: Wed Oct 07, 2009 12:52 am
by Hblade
Lol o.o I know but I didnt know you could do that THAT easy lol :O. And yeah Pyro's code gives me a headache too lol.

Re: real Time Clock - Am and PM, not militarry!

PostPosted: Wed Oct 07, 2009 12:55 am
by DST
So this script you wrote:

Code: Select all
   switch(u.hour)
    {
        case 13:
        Hour = 1;
        break;
        case 14:
        Hour = 2;
        break;
        case 15:
        Hour = 3;
        break;
        case 16:
        Hour = 4;
        break;
        case 17:
        Hour = 5;
        break;
        case 18:
        Hour = 6;
        break;
        case 19:
        Hour = 7;
        break;
        case 20:
        Hour = 8;
        break;
        case 21:
        Hour = 9;
        break;
        case 22:
        Hour = 10;
        break;
        case 23:
        Hour = 11;
        break;
        case 24:
        Hour = 12;
        break;
    }


is equal to:
Code: Select all
Hour=u.hour-12;


Just throwing that out there.