Utilizing the system clock

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
guo
Metal Slime
Posts: 749
Joined: Fri Dec 04, 2009 9:12 pm

Utilizing the system clock

Post by guo »

Hi!

I'd like some advice or examples on utilizing the system clock.

Some examples:

A training minigame that can only be used once per (realtime) day/hour/whatever.
Having NPCs appear on set days of the week

Similar to Surfasaurus but for different end results.
Any help much appreciated!

-G
vvight.wordpress.com
User avatar
kylekrack
Liquid Metal Slime
Posts: 1240
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

I haven't personally written anything that uses, them, but the Time Functions in the plotscripting dictionary are a good place to start:

http://hamsterrepublic.com/ohrrpgce/doc ... 0Functions
My pronouns are they/them
Ps. I love my wife
User avatar
SwordPlay
Chemical Slime
Posts: 966
Joined: Sun Jan 22, 2017 9:32 am
Location: London, England
Contact:

Post by SwordPlay »

This is totally my jam. Except users can change their system time to cheat :(
You might want to (additionally) consider using game-time for some things.

there might be a few ways to use the time.

Broad Usage:
- things on cooldown. similar to how mobile/f2p games have cooldown timers
- special events after real time has elapsed. could be used to measure out rewards or gameplay
- events occurring on specific days of the week, or at certain times.
- perhaps like a day/night or season cycle

Specifically:
- prevent players from abusing/spamming powerful gameplay loops
- ration out rewards or punishments. administer (special) gameplay in doses
- way to reward persistent players. or increase challenges over time.
- celebrate or commemorate specific days or times
- encourage/discourage playing at certain times/days...years etc.,

Stuff like that? I really want to see devs use the in-game and system clock for more things, it's an under-rated tool.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

You can use this script by James to work out what day of the week it is.

If you want to allow something (e.g. a making a wish) only every real-world hour, you can do something like this:

Code: Select all

global variable, begin
 100, last wish hour
 101, last wish day
end

plotscript, make a wish, begin
   # Technically you should also check that the month and year are the same, but it's very unlikely that the player
   # will next try to wish on exactly the same hour of the same day of a different month.
  if (system hour == last wish hour && system day == last wish day) then (
    show textbox (45)  # "Come back later!"
    exit script
  )

  show textbox (46)  # "What do you wish?"
  last wish hour := system hour
  last wish day := system day
end
Note that this lets you make a wish at 3:59 and another at 4:00. If you instead want to require at least 60 real-world minutes before you can wish again, you need to count total number of minutes, e.g.: +

Code: Select all

total minutes := system minutes + 60* system hours + 60*24 * system days + 60*24*31 * system months + 60*24*31*12 * system years
And then you can test "if (total minutes >= last wish total minutes + 60)".
OK, so this is not the right number of minutes in a month or year, it can only be used to tell you whether the number of minutes elapsed is at least some amount, if you want the actual amount, then adapt James' day-of-the-week script.

Obviously we need to add builtin script commands to get the ttotal number of play and system seconds.
User avatar
guo
Metal Slime
Posts: 749
Joined: Fri Dec 04, 2009 9:12 pm

Post by guo »

Thanks! Exactly what I was looking for , TMC.
vvight.wordpress.com
User avatar
Bird
Slime Knight
Posts: 227
Joined: Thu Jan 26, 2012 2:19 pm
Location: Germany

Post by Bird »

It was already mentioned, that the current play time might be useful, too. Here is an example script for a blacksmith, who takes 5 minutes to forge you something. He will tell you, how much time he still needs.
The command "minutes of play" doesn't give you the total minutes of how long the game was played. It must be calculated back by using "hours of play" and "days of play".

Code: Select all

global variable (1,smithready)

plotscript,forgeit,begin
# Total minutes of play + 5 minutes 
smithready := days of play * 1440 + hours of play * 60 + minutes of play + 5
end

plotscript,blacksmith,begin
variable (timestamp)
timestamp := days of play * 1440 + hours of play * 60 + minutes of play
clear string (1)
clear string (2)
clear string (3)
if (timestamp > smithready) 
then ( $1 = "Your goods are ready! Take them." )
else (
  $1 = "Give me some more time! "
  append number (2,smithready -- timestamp)
  $3 = " more minutes!"
  concatenate strings (2,3)
  concatenate strings (1,2)
)
show string (1)
end
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

BTW Bird, you should write "if (timestamp >= smithready)" instead of "if (timestamp > smithready)", because that script might display "Give me some more time! 0 more minutes!"

Also, it's possible to combine the contents of the 'else' block into one line:

Code: Select all

string sprintf(1, $1 = "Give me some more time! %d more minutes!", smithready -- timestamp)
Post Reply