Printing a variable in a message

Misstrace
23 Dec 2015, 13:34
So for the past few days I've been going over the tutorial and searching the forums but no luck here.

I'm trying to create a clock the player can look at to see how long they've been playing. So I created a timer that activates at the beginning of the game, I figured that out, that's easy. However everything else after that has just been a nightmare. So the thing is I can't even check if my scripts are STORING the information of the timer correctly because I can't look at it. If it's mentioned in the tutorial I haven't seen it, and the only references I can find on the forums are a post from 6 years ago when apparently the code formatting was COMPLETELY different and a post only 3 years old which actually says, although I'm paraphrasing, "displaying a variable in a message is too complicated for you and you'd already have to know how to code." Like literally the complete antithesis of why I'm using the program altogether, and certainly not how its advertised.

Here's my current attempt to make this clock work:

I have an object clock, looking at it shows the time. It has two attributes, min and hour, which are set as integers to make it 23:32 from the start of the game. My timer, every 60 seconds, does this:

    <script><![CDATA[
clock.min = clock.min+ 1
if (clock.min >=60) {
clock.hour = clock.hour + 1
clock.min = 0
}
if (clock.hour = 24) {
clock.hour = 0
}
]]></script>


Now I looked up a post about making clocks on this forum before and it had a code to make the clock read "05" and the like when it was less than 10min past the hour, however, again, the code for that is 6 years old and I don't know how to add "set string" in the normal windowed interface so that's just... I mean I give up, I'm not even going to try, because frankly I don't think it's possible.

So now all I have to do to check that I've set up the timer and attributes/variables right is to print a message showing me the time.

Oh but I can't do that.

I've tried %clock.min% and "clock.min" and even just clock.min and none of these do anything except barf out an error.

So if you need more info about what I'm doing with the timer or the clock object or the scripts or anything else just let me know, but I'm basically certain the issue is that I don't know how to tell the message to print variables instead of text.

Thanks in advance,
Misstrace

The Pixie
23 Dec 2015, 13:58
Printing a value is easy. Just go to the description part of the clock, and type in something like:
You look at the clock, it is {clock.hour}:{clock.min}.

The bit in curly braces is a text processor instruction (a relatively recent addition to Quest, and absent from the tutorial I think), and will print the value of the attribute of the clock object. In a script, you could do:
msg("You look at the clock, it is {clock.hour}:{clock.min}.")

... which again uses the script processor, or (and this is in the tutorial):
msg("You look at the clock, it is " + clock.hour + ":" + clock.min + ".")

If you want to always have two digits for your minutes, that will be more complicated...

HegemonKhan
23 Dec 2015, 16:50
'time and date' coding isn't that easy to do... (as I've found out myself personally, lol)

quest uses Attributes to store values:

player.strength = 100
player.alias = "HK"

and the 'msg' Script, is for displaying the Attributes (and~or text):

Text Only (static messages):
msg ("Hi, my name is HK.")
// outputs: Hi, my name is HK.

VARIABLE (Attribute Variable) Only:
player.alias = "HK"
msg (player.alias)
// outputs: HK

just like with algebraic substitution:

x = 100
y = x + 50
// y = 150

we can use concatenation to work with 'TEXT' and 'VARIABLES' together:

x = 100

msg ("The value of x is " + x + ".")
// outputs: The value of x is 100.
~ OR (using the text processor commands) ~
msg ("The value of x is {x}.")
// outputs: The value of x is 100.

---

dynamic messages uses VARIABLES (usually Attributes):

player.alias = "HK"

msg ("The player's name is " + player.alias + ".")
// outputs: The player's name is HK.
~OR~
msg ("The player's name is {player.alias}.")
// ouputs: The player's name is HK.

player.alias = "Misstrace"

msg ("The player's name is " + player.alias + ".")
// outputs: The player's name is Misstrace.
~OR~
msg ("The player's name is {player.alias}.")
// ouputs: The player's name is Misstrace.

------

for non-coders, the text processor commands are much easier to use (to use correctly), as it's quite a bit more complex to do the normal Attribute+text coding, you got to understand the chunks...

viewtopic.php?f=18&t=5559&p=39951#p39951

if you're interested in trying to learn this code stuff better