Can a number be converted into text in I7?

Hey all.

Finally getting back into IF after a long hiatus. I’ve been going through some feedback on a class regarding “Trinity Reimagined” and I’ve come across an interesting thing. We’re using the same “paced time” concept that Trinity used, where you get four turns per minute. I’ve noticed that the common solution just about everyone tries is this:

To say paced-time:
  let current-time be the minutes part of the time of day;
  if seconds > 9, let current-time be "[current-time]:[seconds]".

The problem there, of course, is that current-time is said to be a number but it’s now being asked to hold text.

Again, the above is the solution that most people seem to come to, even the non-programmers in my group. The programmers in the crowd want to know if there is explicit conversion possible (essentially, casting) in these cases.

I know Eric Eve’s extension “Variable Time Control” uses indexed text for this purpose. Is that the best way to go about this? Or is there a way to say that current-time (a number) can have a string representation? I’m not shying away from indexed text necessarily; I’m just looking for the simplest conceptual thing that will work.

No, that’s not possible; a number is a number. I think that the easiest way to do what you want to do is to change the output for time of day. For brevity, this example just uses a “00” in place of the seconds, but you can replace this with your own code as needed:

[code]Test is a room.

To say time of day:
say “[if hours part of the time of day is greater than 12][hours part of the time of day - 12][otherwise][hours part of the time of day][end if]:[if minutes part of the time of day < 10]0[end if][minutes part of the time of day]:00 [if hours part of the time of day is greater than 11]PM[otherwise]AM[end if]”

When play begins:
change right hand status line to “[time of day]”[/code]

Basically, the code redefines the meaning of time of day for “to say” phrases, forcing a third printed parameter. If you only want seconds displayed in certain cases, you could add a condition to the end of the “to say” preamble, or call it “to say time of day plus seconds” and call that as needed.

–Erik

Thanks for the response, Erik.

I did originally have an example that did sort of what you did with say phrases but then I started people down a path that would eventually let them see how “Variable Time Control” was created. This counter-example is actually good, in a way, because I’m going to use this as an example of how you can’t do certain things. Along with the example I posted, others tried stuff like this:

The current-time is text that varies.

To say paced-time:
    let current-time be the minutes part of the time of day;

That, of course, doesn’t work for the exact same reason as the first example, this time because minutes are being used with something that was originally established as text. I find that taking people through these “mis-steps” is really helpful to learning Inform. This will also let me get the indexed text into my tutorials a little earlier than I would have.

Hey! Welcome back Jeff!

To catch all the cases, I think you need to add “[if hours part of the time of day is less than 1][hours part of the time of day + 12]”, or 12:30 AM will display as 0:30 AM. Suddenly the 24-hour clock is very appealing.