How do I make a ingame Clock with Weekdays

Get help using Construct 2

Post » Mon Nov 24, 2014 10:03 am

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.
B
8
S
2
Posts: 53
Reputation: 687

Post » Mon Nov 24, 2014 10:32 am

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)
B
17
S
3
G
3
Posts: 89
Reputation: 2,825

Post » Mon Nov 24, 2014 10:44 am

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
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093

Post » Tue Nov 25, 2014 5:43 pm

Thank you - i will test it.
B
8
S
2
Posts: 53
Reputation: 687


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests