How do I make a ingame Clock with Weekdays

0 favourites
  • 4 posts
From the Asset Store
The clock has started ticking, but are you fast enough?
  • How do I make a ingame Clock with Weekdays? I want to make a Game which need a ingame Clock (but no System Clock)

    Example:

    Monday - 22:30 >> When 23:59 is reached, the Clock should get back to 00:00 and the day have to change to Tuesday. The Player should can speed up the gametime per trigger.

    I need the InGame Clock for a builing game like SimCity or Rollercoaster Tycoon. I only know that i need some variables and Text-Objects - here i make one Text-Object for the Days -

    Every tick set Daytext to Day - Then i need Subevents for each Day (if it is Mon -> Set Day to Tuesday.. and so on for each day), but now i need another condition with the Daytime (if it is 00:00 set next day to) and for this i need the Clock.

  • Hi, I would suggest using a value for each of the following: Hours (number) - Minutes (number)- Seconds (number) - Week days (number).

    You can do, On Layout Start:

    Set WeekDay = 1

    Set Hours = 0

    Set Minutes = 0

    Set Seconds = 0

    On every 0.25 seconds:

    If Weekday = 1 Set Daytext to: "Monday" &"-" &Hours &":" &Minutes &":" &Seconds

    If Weekday = 2 Set Daytext to: "Tuesday" &"-" &Hours &":" &Minutes &":" &Seconds

    If Weekday = 3 Set Daytext to: "Wednesday" &"-" &Hours &":" &Minutes &":" &Seconds

    Etc...

    On every 1 second:

    Add +1 to Seconds

    If Seconds greater or equal to 60 then add 1 to minutes AND set Seconds to 0

    If MInutes greater or equal to 60 then add 1 to hours and set minutes to 0

    If hours greater or equal to 24 then add 1 to weekdays and set hours to 0

    If weekdays greater or equal to 7 set 0 to every value

    I just wrote this on-the-fly and might be missing some things but you have the general idea. There is perhaps an easier way to do this but this is what just came up to my mind. Hope it sets you on the right track.

    However, make sure you can check the transitions between days are smooth.

    You should also consider saving these values to text files in the user's documents in order to be able to retrieve them when you close/re-launch the game (Node-Webkit object). If you do so, consider discarding what I wrote at the beginning (On Layout Start: Set WeekDay = 1) but replace it with

    On Layout start : if file exists set your values to each existing file

    if doesn't exist then create the file. (use the "i" keyboard shortcut to invert a condition)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you have only weekdays (aka. Nothing like "Monday, the 31st of september"), with the clock being precise at the minute, you could start at monday, 00:00 for the minute 0, one minute later, monday 00:01, the minute 1, one hour later, monday 01:01, the minute 61, etc...so you count the number of minutes between monday 00:00 and sunday 23:59.

    Number_of_minutes% 60= digits of the minutes

    (Int(Number_of_minutes/60))% 24= digit of the hours

    (Int(Number_of_minutes/1440))% 7= digit of the day (0 for monday, 1 for tuesday, ..., 6 for sunday)

    So you just add up the number of minutes and use those three calculs to retrieve each info, the formulas may be wrong (also 1440 is 24*60 if you wondered).

    Edit: ninja'd, both solutions should work so take the one you prefer

  • Thank you - i will test it.

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