Making a simple 12 hour clock

For questions about using Classic.

Post » Wed Dec 02, 2009 3:33 am

I'm making a simple 12 hour clock system where it shows only numbers instead of using an image of a clock. I've set up the minute to be 5000 millisecond per minute so that its faster than the real minute.
Well basically it works, except for one thing, I can't seem to make the AM-PM textbox change from AM to PM and PM to AM.

My current code is:
If global variable "Hour" = 12 and textbox = "AM"
then textbox = "PM"

If global variable "Hour" = 12 and textbox = "PM"
then textbox = "AM"

Something like that. It works only once, like from AM it goes to PM, but it doesnt work after that. What could be wrong?
B
10
S
5
G
8
Posts: 203
Reputation: 4,395

Post » Wed Dec 02, 2009 4:55 am

Order of events.

[code:2vm729ga]
+ Foo = 1
-> Change Foo to 2

+ Foo = 2
-> Change Foo to 1
[/code:2vm729ga]

At first glance you would think that this would toggle Foo back and forth between 1 and 2... but it doesn't. Foo will always be 1.

The reason is that the first event changes Foo to 2, then you immediately go into the second event... which says if Foo is 2, change it to 1.

What you need is something like this:

[code:2vm729ga]
+ Foo = 1
| -> Change Foo to 2
|
+ Else
-> Change Foo to 1
[/code:2vm729ga]

"Else" is a special condition that links to the previous event. It sort of turns the two events into one, which takes care of the order of events problem.

Alternately, you could make a switch, like so:

[code:2vm729ga]
+ Always
-> Set global('switchAMPM') to "yes"

+ Global('hour') = 12
+ Text.Text = "AM"
-> Set Text.Text to "PM"
-> Set global('switchAMPM') to "no"

+ Global('hour') = 12
+ Text.Text = "PM"
+ Global('switchAMPM') = "yes"
-> Set Text.Text to "AM"
[/code:2vm729ga]

Of course, you would also need a condition to only trigger the switch once for every time the clock ticks over to 12, otherwise all during the hour of 12 you will have the AM/PM swapping every other tick.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Dec 02, 2009 5:49 am

I tried the first one and I noticed that in the duration that the hour is 12, PM and AM keeps exchanging each other. I think that while the global variable hour is 12, my event with the else condition is looped until hour becomes 1.

The event is checked every tick right? Then there could be like a number of ticks while hour is equal to 12, therefore they keep exchanging each other.

EDIT: Ok, I got it working, I just needed to a counter to be added in the "If hour is 12" condition. Basically, I made it like this:

If Hour = 12 and PMAM = 0 then PMAM =1 and do the exchanging of PM into AM and vice versa.

Then another event goes like: If Hour = 1 then PMAM = 0.

Thanks for the Else tip!!
B
10
S
5
G
8
Posts: 203
Reputation: 4,395

Post » Wed Dec 02, 2009 5:52 am

[quote="TheJanMan":d3o9avo0]I tried the first one and I noticed that in the duration that the hour is 12, PM and AM keeps exchanging each other. I think that while the global variable hour is 12, my event with the else condition is looped until hour becomes 1. [/quote:d3o9avo0]

[quote="deadeye":d3o9avo0]Of course, you would also need a condition to only trigger the switch once for every time the clock ticks over to 12, otherwise all during the hour of 12 you will have the AM/PM swapping every other tick.[/quote:d3o9avo0]
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Dec 02, 2009 11:16 am

Uhh yeah, I forgot to read that part lolz! Thanks anyway.
B
10
S
5
G
8
Posts: 203
Reputation: 4,395

Post » Wed Dec 02, 2009 8:37 pm

you can do this using the modulus and division operators (math yay!)
I worked out the solution on chat the other day but you left too quickly to see it. I don't feel like going over it again >_<
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests