0 votes
by (640 points)
How do I make text change (loop) while displayed in a passage?

For example I want "this text" to be changed to "that text" while being displayed. I've seen this done in some games where a line of text constantly loops between a number of different sentences.

What is the script for this?

1 Answer

+1 vote
by (63.1k points)
edited by
Best answer

I assume you mean something like this: 

<<set _text to ["hello", "welcome", "hey", "greetings"], _i to 0>>\

  <<repeat 1s>>
    <<set _i++>>
    <<replace "#cycling-text">>\
      <<= _text[_i % _text.length]>>\

Warning: I didn't test this code, so it's possible I made a mistake. 

by (640 points)
edited by
Lovely. This is exactly it. Thanks!

One qustion: Is it possible to speed up the transition? If so, how?

Edit - actually i found an issue with this. Every time the text changes it causes all the text underneath the code to go down one line.


This: https://i.imgur.com/Fkj9TAh.png


This: https://i.imgur.com/HZK5mvS.png
by (63.1k points)
The <<repeat 1s>> line. Change 1s to the time you want in seconds (s) or milliseconds (ms). So, half a second, i.e. twice as fast would be <<repeat 500ms>>
by (63.1k points)
Re: your edit.

Place all the code (the <<repeat>> stuff) in a <<nobr>> macro .
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.