Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Making a Clock

I need help to make a simple, 24-hour clock. Here's how I want it to work:
At the bottom of the screen, it will say menu. When you go to the menu (StoryMenu), the time will be displayed at the top of the screen. I'd prefer this to be done by variables, as I think it would be easier then to add how much time doing certain actions would do, as I'd to make doing certain things take up different amount of times, I.E. Walking down to the mailbox would take 5 minutes, while going down to the post office would take 15 minutes.

I figured this should only take 3 variables at minimum, "Hour", "Minute", and "PM/AM'
So, I want it be able to the following:
-When the minutes get to 60, it will subtract 60 from minutes and add '1' to the hour variable.
-When the hour variable gets to 13, it will display it in the menu as 1, display 14 as 2, etc. (in other words, I want it to be in army time in the variables, but display as regular time in the passages.)
-When the hour is at anywhere from 13-23,0, it will change the variable "AM" to "PM", and when it's anywhere from 1-12, it will change back to AM (This is probably the easiest part)

Also, I'd like that all this would be automated using a Special Passage to check and update them so that I wouldn't need to check and update them at the top of every single passage, so that way the only thing I'd be putting at the top of the passage is how many hours/minutes to add. I don't know if this is even possible though, and while it would be a minor inconvenience, it's not the most important thing for it to be automated.

There would also be a "Day" variable, which would be updated when the time has the hour being '0', where it will take you to a passage letting you know it's the next day, and then you'll be able to pick if your character would go to bed and wake up again at 9:00AM (Every day starts at 9AM) or continue through the night, skipping some rest but allowing access to certain night-only events.
My game is only going to span over one month, so no other variables like month or year would be needed.

So, can anyone help me and tell me how to do this?

Comments

  • Simpler cheat - store and increment a single variable - $time. It contains the time of day in minutes from 0 thru 1440. When you come to do your display it's PM if $time > 720 and the hour is java.math.floor(%time / 60), minutes are time % 60. Just format it up for display and store a single time counter. It's a lot simpler.

    If you need to extend it to cover multiple days, days are floor($time / 1440), am/pm is $time % 720, hours are ($time /60) % 24.
  • edited May 2017
    Oh, I just figured out how to get the clock to work that I originally was using, but your solution is a lot easier.

    Now I have another question though: how do you add and subtract from variables? I think I'm missing something. When I was using $minute and $hour as two separate variables, I was trying to use this to calculate the time whenever going to another passage:
    <<set $minute + 30>>
    <<if $minute gte 60>><<set $minute - 60>><<set $hour + 1>><<else>><<endif>>
    <<if $hour eq 24>><<set $hour - 24

    And then I also tried this:
    <<set $minute = $minute + 30>>
    <<if $minute gte 60>><<set $minute = $minute - 60>><<set $hour = $hour + 1>><<else>><<endif>>
    <<if $hour eq 24>><<set $hour = $hour - 24
    But neither seem to work, as when I <<print>> the variables, they don't change. Am I doing something wrong?
  • edited May 2017
    We had a very similar question that you might be able to adapt to your needs here. If you've already got things figured out, then don't worry about it. More options is never a bad thing, though.
    ... how do you add and subtract from variables? I think I'm missing something. When I was using $minute and $hour as two separate variables, I was trying to use this to calculate the time whenever going to another passage:
    <<set $minute + 30>>
    <<if $minute gte 60>><<set $minute - 60>><<set $hour + 1>><<else>><<endif>>
    <<if $hour eq 24>><<set $hour - 24

    And then I also tried this:
    <<set $minute = $minute + 30>>
    <<if $minute gte 60>><<set $minute = $minute - 60>><<set $hour = $hour + 1>><<else>><<endif>>
    <<if $hour eq 24>><<set $hour = $hour - 24
    But neither seem to work, as when I <<print>> the variables, they don't change. Am I doing something wrong?

    Some notes:

    1. To use the set macro, you need two arguments: the variable to set, and the value to set it to: <<set: [variable] to [value]>>. In your first chunk of code, '$minute + 30' is a value, so it's interpreted by the system as <<set [value]>> and won't work; there's nowhere to store the value. You correctly fixed this for your next example. <<set $minute = $minute + 30>> includes both arguments. You can use a few shortcuts, though:
    <<set $var += 10>> /% equivalent to <<set $var to $var + 10>> %/
    <<set $var -= 10>> /% equivalent to <<set $var to $var - 10>> %/
    <<set $var++>> /% equivalent to <<set $var to $var + 1>> %/
    <<set $var-->> /% equivalent to <<set $var to $var - 1>> %/
    

    2. You have:
    <<if $minute gte 60>><<set $minute = $minute - 60>><<set $hour = $hour + 1>><<else>><<endif>>
    

    You have an <<else>> floating there all by itself, with no associated code or output. You shouldn't do that. <<if [condition]>>Stuff<</if>> is enough--if the conditions aren't met, it'll skip over the whole thing. Having an empty <<else>> isn't necessary.

    The next statement after this isn't complete, but I assume that it is in the actual code.

    3. Your second chunk of code should be changing your variables, so are you sure you're placing your <<print>> macros in a place where they'll be able to see this change? Are they being updated? Are you initializing your variables in the right place--for instance, are you setting them in a place that's causing them to revert before being printed? At any rate, if you're getting the wrong output from your <<print>> macros, there's a problem somewhere. It's not in the <<set>> macros from your second example, though.
Sign In or Register to comment.