Basic time system?

Hello everyone! I was wondering if any of you could help me with a basic time system. I'm looking for four states of the day, morning, afternoon, evening, and night. Each one lasting 36 turns. After the four of them cycle through, I'd like it to repeat so that there is an indefinite amount of days. Ideally, there would also be ways to skip time forward by resting/sleeping. Is there any way to do this easily? As always, thank you for your help in advance.


This is pretty much exactly what I am doing in X3! =)
I made an object called twentyfourhours and added the attribute HoursCount to it. I set this as an integer attribute equal to 0.
Under the script tab of the game element I added this under Run script after every turn in the game.

twentyfourhours.HoursCount = twentyfourhours.HoursCount + 1

I added objects as children of my twentyfourhours representing each time of day. In your case - day, morning, afternoon, evening, and night. I added an object attribute to twentyfourhours and set it to object morning.
I added a changed attribute script to object twentyfourhours. Here I added a massive 'If' script. On the first line If added this:

if (twentyfourhours.HoursCount = 1) {
  twentyfourhours.currenttime = dawn

followed by whatever script I want to run.
Also in the changed attribute script... I added to the original If script an 'Else If' for each time of day. I changed the "1" above to a "36" and the "dawn" to "morning". 72 and afternoon. 108 and noon. Etc, etc...
In the 'thens' for each else if, you can run whatever scripts you want. I had vendors arrive and depart, NPCs move around, messages indicating that the environment had changed, messages about player state, etc.

On your last Else If (180 if my math is correct), I simply added this to the Then:

twentyfourhours.HoursCount = 1

and this would reset the day and everything would start all over again.

The easiest way to add a wait command is to add a command under the game tab. Leave as a command pattern and type something like the following in...

wait until midnight; wait for midnight; wait til midnight; wait till midnight

I had the following as my scripts:

msg ("<br/>You find the most comfortable place to nestle down and hope you make it until midnight.<br/>")
wait {
  msg ("<br/>You wake up and notice that your body is a bit achy from your uncomfortable rest, but it's not too bad.  It is now midnight.<br/>")
}
DecreaseHealth (2)
set (twentyfourhours, "HoursCount", 89)

where 89 is the turn count just before midnight started in my hourscount attribute.

I did this for each time of day, just changing the time of day that I wanted to wait until and the number associated with the turn just before the new time of day was set to begin.

Hope this helps. I can send you a working example if you would like. Let me know. Good luck!


I have a tutorial on how to implement WAIT 10 minutes here:
https://github.com/ThePix/quest/wiki/Enhanced-Waiting


Thank you, both of you! This should help a lot!


@XanMag

Hello! I've followed your instructions but i'm being met with a strange error. It is as follows

Error running script: Error compiling expression 'twentyfourhours.HoursCount + 1': ArithmeticElement: Operation 'Add' is not defined for types 'Object' and 'Int32'

Do you have any idea what this means or a potential fix?


If you want, start a new game. Copy-paste the following code over everything in code view. Top row of buttons, looks like a notecard). This might be a simplified version of what I gave you.

Does that error pop-up when you make your first move/start the game? Make sure everything is properly capitalized. It gets a little finicky with capitalization.

Make sure HoursCount is set as an integer attribute on the twentyfourhours object.

<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Cycling a Day">
    <gameid>d249f751-fa06-4277-875e-79e19b7166aa</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <statusattributes type="stringdictionary">
      <item>
        <key>TOD</key>
        <value>Time of Day:</value>
      </item>
    </statusattributes>
    <object name="TimeOfDay">
      <inherit name="editor_object" />
      <HoursCount type="int">1</HoursCount>
      <currentTOD type="object">morning</currentTOD>
      <changedHoursCount type="script">
        if (TimeOfDay.HoursCount = 1) {
          TimeOfDay.currentTOD = morning
          msg ("It is now morning.")
        }
        else if (TimeOfDay.HoursCount = 6) {
          TimeOfDay.currentTOD = noon
          msg ("It is now noon.")
        }
        else if (TimeOfDay.HoursCount = 11) {
          TimeOfDay.currentTOD = evening
          msg ("It is now evening.")
        }
        else if (TimeOfDay.HoursCount = 16) {
          TimeOfDay.currentTOD = night
          msg ("It is now night time.")
        }
        else if (TimeOfDay.HoursCount = 20) {
          TimeOfDay.HoursCount = 0
        }
      </changedHoursCount>
      <object name="night">
        <inherit name="editor_object" />
      </object>
      <object name="evening">
        <inherit name="editor_object" />
      </object>
      <object name="noon">
        <inherit name="editor_room" />
      </object>
      <object name="morning">
        <inherit name="editor_object" />
      </object>
    </object>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <exit alias="south" to="room2">
      <inherit name="southdirection" />
    </exit>
  </object>
  <object name="room2">
    <inherit name="editor_room" />
    <exit alias="north" to="room">
      <inherit name="northdirection" />
    </exit>
    <exit alias="south" to="room3">
      <inherit name="southdirection" />
    </exit>
  </object>
  <object name="room3">
    <inherit name="editor_room" />
    <exit alias="north" to="room2">
      <inherit name="northdirection" />
    </exit>
  </object>
  <object name="Warehouse">
    <inherit name="editor_room" />
  </object>
  <turnscript name="HoursCounter TS">
    <enabled />
    <script>
      TimeOfDay.HoursCount = TimeOfDay.HoursCount + 1
    </script>
  </turnscript>
</asl>

Ignore the time of Day thing in the inventory bar. I'm trying to figure out how to display the TOD there. =)


Palatheio, the error is because you have not set a starting value for twentyfourhours.HoursCount. You need to set it up on the attributes tab in the desktop version, or in the start script of the game object like this:

twentyfourhours.HoursCount = 1

Thank you so much! I've managed to reverse engineer what you've pasted here, and after a significant amount of errors, everything seems to be working. Thank you so much!

Also thank you Pixie, not just for this, but for all of your libraries and help on other topics. I can't thank you two enough!


Wow, XanMag, thats a great way to work on a time of day, Think I'll use the ideas to rework the very basic weather /day and night functions i have in my game now..


also, there's the modulus (%) operator/operation, which is division, but it gets the remainder, which has the applications of cyclic and/or factoring (odd/even, factors: divisible by X number), and cyclic is useful for time coding.

game.hour_count = 0
game.hour_count = game.hour_count + 1

game.military_hour_clock = game.hour_count % 24
game.civilian_hour_clock = game.hour_count % 12

game.hour_count = 0
military: 0
civilian: 0

game.hour_count = 1
military: 1
civilian: 1

game.hour_count = 11
military: 11
civilian: 11

game.hour_count = 12
military: 12
civilian: 0

game.hour_count = 13
military: 13
civilian: 1

game.hour_count = 23
military: 23
civilian: 11

game.hour_count = 24
military: 0
civilian: 0

game.hour_count = 25
military: 1
civilian: 1

game.hour_count = 35
military: 11
civilian: 11

game.hour_count = 36
military: 12
civilian: 0

game.hour_count = 37
military: 13
civilian: 1

game.hour_count = 47
military: 23
civilian: 11

game.hour_count = 48
military: 0
civilian: 0


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums