Making a simple 12 hour clock

This forum is currently in read-only mode.
From the Asset Store
Set of 12 Parallax Background to make pixel art game.
  • 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?

  • Order of events.

    + 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.
  • 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!!

  • 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.

    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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Uhh yeah, I forgot to read that part lolz! Thanks anyway.

  • 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 >_<

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)