Clock

I should have posted this before I started making a game... but, that's how I roll...

With every move in the game, I have a '+1' script running. I would like to sync this with my digital alarm clock.

Game starts at 11:15pm. Five turns pass and it is 11:20. I would like the clock to reflect that.

It is a pretty short game, only lasting 45-60 turns, and I probably could do 45-60 Else If scripts to print out the time on the clock...

x clock
Else If Integer Count = 27, then print message "the clock reads 11:42"
Else If Integer Count = 28, then print message "the clock reads 11:43"

etc, etc...
Seems like a pain in the ass, but certainly doable.

Is there an easier way without janking up the stuff I have already implemented? I do NOT want a time posted in any panes or anything like that. It's only relevant when the clock is examined.

Thanks in advance.


K.V.
x = game.timeelapsed
game.hours = x / 3600
time = x%3600
game.minutes = x/60
x = time%60
game.seconds = x
msg ("<br/>Game time: " + game.hours + ":{if game.minutes<10:0}" + game.minutes + ":{if game.seconds<10:0}" + game.seconds + "<br/>")

K.V.

I believe this is what you REALLY want:

    <start type="script">
      clock.x = 15
      clock.time = "11:"+clock.x
    </start>
   <object name="clock">
      <inherit name="editor_object" />
      <look>It reads: {clock.time}.</look>
    </object>
  <turnscript name="ClockScript">
    <enabled />
    <script>
      clock.x = clock.x + 1
      if (clock.x = 45) {
        clock.time = "12:00"
        //msg ("You ran out of time!<h3>YOU SUCK!</h3>")
        //finish
      }
      else {
        clock.time = "11:"+clock.x
      }
    </script>
  </turnscript>


Clocking

You are in a room.

You can see a clock.

> look at clock
It reads: 11:15.

> look at clock
It reads: 11:16.

> look at clock
It reads: 11:17.

> look at clock
It reads: 11:18.

> look at clock
It reads: 11:19.

> look at clock
It reads: 11:20.


If you already have a Count variable, then…

msg ("the clock reads "+((((Count + 15)/60+10)%12)+1)+":"+Left("0"+((Count+15)%60),2))

or a rough approximation of what it looks like in the GUI:

  • print message [expression] "the clock reads "+((((Count + 15)/60+10)%12)+1)+":"+Left("0"+((Count+15)%60),2)

I'm making a clock tutorial now. (Half serious, half sarcastic, half angry and furious, half tired) I hope you're happy!


...Nevermind. The closest I got was printing that it was "Military Time: 9:0".

You can paste this on the look thing, to show the time.

Military Time: {game.hour}:{game.minute}

So if I type in "Military Time: {game.hour}: {if game.minutes<10:0} {game.minute}" I get:
Military Time: 9: {if game.minutes<10:0} 0

That figures....


Military Time: 9: {if game.minutes<10:0} 0

Hmm... trying to remember the restrictions in text markup. Is it that it supports = but not <? Or is it that the {if requires an else clause (in which case {if game.minutes<10:0:} might work?


Mrangel, I tried

{if game.minutes<10:0:}

but it didn't work. It might be the first thing, or some other thing.


here's the doc for quest's text processor commands (if you're working with JS/outside of quest, then you can probably ignore this post):

http://docs.textadventures.co.uk/quest/text_processor.html

it's much more limited (though you can nest a bunch of 'ifs' I think), so you might just have to do 'normal' (the 'if' and String Concatenation) scripting


maybe try this:

{if game.minutes<10:0}:

// or:

"{if game.minutes<10:0}:"

// or:

"{if " + game.minutes + "<10:0}:"

I'm using the online version. So no.

I'm just here to try and help XanMag anyway. It looks like he's already got everything under control.


try:
M=right("0" +game.minutes,2)
this will add a "0" in front of the minutes so that you get:
00, 05, 10, 15...

Oh... mrangel already said that... (just longer...)


K.V.

game.timeelapsed is a built-in attribute.

x = game.timeelapsed
game.hours = x / 3600
time = x%3600
game.minutes = x/60
x = time%60
game.seconds = x
msg ("<br/>Game time: " + game.hours + ":{if game.minutes<10:0}" + game.minutes + ":{if game.seconds<10:0}" + game.seconds + "<br/>")

msg ("<br/>Game time: " + game.hours + ":{if game.minutes<10:0}" + game.minutes + ":{if game.seconds<10:0}" + game.seconds + "<br/>")

This is the proper syntax {if game.minutes<10:0}.

If you're trying to print that on the first turn, you have to use a SetTimeout(1) to give Quest a second to assign a value to game.timeelapsed.


NOTE: This must be in a turn script to work, too.


Here is an example game:

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Easy clock example">
    <gameid>21b48b6c-a07f-4da3-a955-a1180f2d632c</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <start type="script">
      SetTimeout (1) {
        ClockFunct
      }
    </start>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <turnscript name="ClockTurnScript">
    <enabled />
    <script>
      ClockFunct
    </script>
  </turnscript>
  <function name="ClockFunct"><![CDATA[
    x = game.timeelapsed
    game.hours = x / 3600
    time = x%3600
    game.minutes = x/60
    x = time%60
    game.seconds = x
    msg ("<br/>Game time: " + game.hours + ":{if game.minutes<10:0}" + game.minutes + ":{if game.seconds<10:0}" + game.seconds + "<br/>")
  ]]></function>
</asl>

image


jmne,

  1. Did you have it in a start script?

It won't work on the first turn without a SetTimeout


  1. Did you change it around some?

You have game.hour. I have game.hours.

I also noticed you put game.minute in one place and game.minutes in another, all in the same line of code...


K.V.

Here it is as a two-minute countdown:

<function name="GameTimeFunction"><![CDATA[
  x = 120 - game.timeelapsed
  time = x%3600
  game.minutes = x/60
  x = time%60
  game.seconds = x
  if (game.seconds < 10) {
    secondsDisplayed = "0+"game.seconds
  }
  else {
    secondsDisplayed = game.seconds
  }
  game.timeDisplayed = game.minutes + ":"+secondsDisplayed
  msg ("<center><br/><b>[SYSTEM MESSAGE: Game-time remaining: "+game.timeDisplayed+" ]</b><br/></center>")
  ]]></function>

Start Script

SetTimeout (1) {
  ClockFunct
}

Turn script

ClockFunct

image


Without the SetTimeout on the start script:

image


Just an FYI. KV's first suggestion worked like a charm for me. Thanks.

But... feel free to keep talking about clocks. =)


K.V.

How many clocks can you count in opening of Back to the Future?


Military Time: {game.hour}:{if game.minute<10:0}{game.minute}

This works.

*Loser trumpet/trombone plays

Brie-brie-brieeeeeeeee.......


How many clocks can you count in opening of Back to the Future?

Total guess...


To add a leading zero, yu can use PadString.
http://docs.textadventures.co.uk/quest/functions/string/padstring.html

You could use it like this:

It is {=PadString(hours, 2 0}:{=PadString(minutes, 2 0}.


K.V.

@ The Pixie

Nice!

I peruse the functions frequently, but there are still many that have slid right past me.

We should do up a Function of the Week thread.

☆The more you know...

(Remember that? During the commercial breaks when G.I. Joe, He-Man and She-Ra and all those cartoons originally ran?)


How many clocks can you count in opening of Back to the Future?
Total guess... 22.

That's the count I come up with, too. (Have you ever noticed the 'clock tower' clock, with the little man hanging from it? Because I never have until just now. I just found a 32-year-old Easter Egg! Whoo-hoo!)


🎵 Bum Bum-bah-BAH!!!

Hear ye, hear ye!


jmnevil54, an up-and-coming Quest Time Lord, has now coded a functional clock.

What will this mean for the players? Will there be time-trials?

More on this as it comes in...


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

Support

Forums