It looks like you're new here. If you want to get involved, click one of these buttons!
(set: $time to 0)
Then, at the start of every phrase, let's put the code to use.
(live: $time + 1)[Phrase one]
(live: $time + 1)[Phrase two]
(live: $time + 1)[Phrase three]
(live: $time + 1)[Phrase four]
ISSUE: (live:) needs the letter s for seconds (as well as ms to milliseconds). I tried:
(live: $time + 1 + "s")[Didn't work, clearly]
(live: (print: "$time + 1") + (print: "s"))[Didn't as well]
I ask for two things:
Comments
You could use something like this for a timed append: You could use something like this for a timed replace:
(live:)
macro takes are not strings and you cannot treat them that way. They are numbers, specifically numeric literals which include a temporal unit (e.g.1s
represents 1 second or 1000 milliseconds).AFAIK, they decompose into the appropriate number of milliseconds and that's also what
(live:)
actually takes, time in milliseconds (though that's an implementation detail, which you shouldn't worry about).For example, the append example I gave above could also be done as: Though, you don't need a $variable for something simple like that (which is why my original example didn't use one).
I'm not a native english speaker, so help me with this: append is like adding? Eg: Phase One will become Phase One, Phase Two?
That's not what I want. It's a dialogue that appears as seconds passes, so replacing isn't my thing. There's another problem I'll tell you just below:
I didn't say they were strings. That's exactly my problem, as twine doesn't add 1 (as 1 second) and s (the letter you need to put next to the number in (live:) macro).
But I have a bunch of lines of dialogue. I want something like: this dialogue will come, then this one will, then this one, then this one, one after another for, like, thirty lines.
Is that possible?
If not, I'll do the (live: 1s) through (live:30s), but it would be awesome if I could do (live: $second + 1) thirty times.
So the "timed-append" hook has the text "Phrase one"
When you do "timed-append" will now say "Phrase one, Phrase two"
I have a simple way of doing a timed conversation that uses an array and
(move:)
that worked when I wrote it, but doesn't work today. Here's a variant of my example that still works. This doesn't do exactly what you want, but it might be useful. The array example (when it worked) basically worked the same way, but used "(move: $slowtext's 1st into $x)
" instead of "(set: $c to (substring:$slowtext, $x, $x))
"NOTE: I'm not sure it's a good idea to split a string variable over multiple lines the way I do in that example, but I don't know of a different way to get line breaks in there.
You can also get an interesting effect if you change "
(append:?story)[$c]
" to "(append:?story)[(t8n:"dissolve")[$c]]
"(move: $slowtext's 1st into $x)
" instead of "(set: $c to (substring:$slowtext, $x, $x))
"NOTE: I'm not sure it's a good idea to split a string variable over multiple lines the way I do in that example, but I don't know of a different way to get line breaks in there.
You can also get an interesting effect if you change "
(append:?story)[$c]
" to "(append:?story)[(t8n:"dissolve")[$c]]
"I like this but I can't really understand it. Would I be asking too much for a more detailed explanation? For instance, what the substring macro does or what these letters $x or $c do?
$c
is a character. Actually, it's really a string that we're going to make sure is only 1 character long. My day job again, sorry.$x
is a terribly named iterator. It contains the index of the next character of $slowtext that we want to print.Every 100ms, we want to print the next character of $slowtext. Here's how we accomplish that: Strings (and everything else) in Harlowe's syntax is 1-based, so the first character of the
$slowtext
string is character 1. This just initializes$x
so that when we start printing characters from the string, we'll start at the beginning of the string.(live:)
- This, as I believe you already know, will do everything between the [ ] every 100ms.(substring:$slowtext,$1,$5)
will get you the 1st to the 5th character of$slowtext
. In this case, we only want one character (the next one to print), so we get characters$x
to$x
and assign them to the variable$c
. should probably be written as(if: $c is not "")
, or(unless: $c is "")
. will be empty if the substring function couldn't get any text because we started after the end of $slowtext. This makes sure that we don't just keep printing empty strings or blow up the browser after $x becomes a huge number.(append:)
is what actually adds $c onto the end of the text in the story hook. increments $x so that we will print the next character the next time the code in(live:)
is called. (Otherwise we would just print the same character again)Hope that clarifies things a bit!
You can use \n to insert a newline into a string.
$slowtext
string is character 1. This just initializes$x
so that when we start printing characters from the string, we'll start at the beginning of the string.(live:)
- This, as I believe you already know, will do everything between the [ ] every 100ms.(substring:$slowtext,$1,$5)
will get you the 1st to the 5th character of$slowtext
. In this case, we only want one character (the next one to print), so we get characters$x
to$x
and assign them to the variable$c
. should probably be written as(if: $c is not "")
, or(unless: $c is "")
. will be empty if the substring function couldn't get any text because we started after the end of $slowtext. This makes sure that we don't just keep printing empty strings or blow up the browser after $x becomes a huge number.(append:)
is what actually adds $c onto the end of the text in the story hook. increments $x so that we will print the next character the next time the code in(live:)
is called. (Otherwise we would just print the same character again)Hope that clarifies things a bit!
I like this. I'll try this on, but be sure it's just a workaround, as what I keep not being able to do what I wanted, that is, print phrase by phrase.
Huh. Yeah, that works. Since HTML seems to be escaped when printing strings, I was afraid backslashes would also be. (In retrospect, I wasn't thinking this through. It looks to me like when I put \n into a string in the editor, the string ends up containing a newline character. As it should. '<' and '>' are most likely stored as '<' and '>' and escaped during printing)
If you just want each phrase to appear as-is, you should try something like this: Note that
time
is not the same as$time
- it has no $ sigil because the program controls it, not the author. The meaning of $ is simple: the variable is under the author's control, not the program's.The 1s given to (live:) refers not to the time in which the phrases appear, but the frequency in which the live hook's contents is re-run. (live: 1s) means "rerun this hook's code every 1 second".
@angelodias: Remember to use a (stop:) macro after you have shown your last Phase because the above will keep rendering every second until you do something that stops it
I'm very happy with the answer but it still doesn't solve my issue.
I don't want to insert 1s, 2s, 3s, ... 30s, 31s, 32s etc. I want to insert a code that increases the value each second and play with each new value. Then, I'll have to write only one line and repeat it.
like this:
Here you go:
Thank you VERY much! I'll try this right away!
And, differently from what you think, I always try a lot before asking something. I'm not a programmer and my true problem (which I'm trying to overcome) is thinking like a programmer. Twine is being a nice experience of try-and-error. Sorry if I "sounded wrong"