Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Replace and remove text multiple times + timed replace

Hello all,

After spending another hour trying to figure this out on my own, I'm just going to ask here:

In my game scenario, a TV set is on, and the anchor is speaking several lines one after another. What I'm trying to do is:

-- TV text line 1 is present

-- TV text line 2 replaces line 1 in the exact same spot (line 1 is gone now)

-- TV text line 3 replaces line 2 in the exact same spot (line 2 is gone now)

While I can manage to replace line 1 with line 2 using click-replace, I don't know how to replace line 2 with line 3.

SEPARATELY

I may want to instead use a timed replace to create a sense of urgency of what's running on the TV. In this scenario I would need:

-- Text line 1 to appear for, say 5 seconds

-- Text line 2 to appear for 5 seconds in same spot as line 1 (line 1 is gone now)

-- Text line 3 to appear for 5 seconds in same spot as line 2 (line 2 is gone now)

And then the TV dies -- so all lines disappear in either scenario leaving: The TV goes dead.

Help? And apologies for the unending Qs...I'm hoping to nail 5-6 game elements and then just use those in different ways, not keep applying more...

Comments

  • The following solutions use an array to store the lines of text you want to appear on the TV, I did this to make the lines easier to edit and so that the code is a little more generic.
    They also use the Javascript Array shift() function to extract the first item out of the lines array.

    1. Link based text updating:
    (set: $lines to (array: "TV text line 1", "TV text line 2", "TV text line 3"))
    
    |tv>[(print: $lines.shift())]
    
    |link>[
    	(link-repeat: "Continue")[
    		(replace: ?tv)[(print: $lines.shift())]
    		(if: $lines's length is 0)[
    			(replace: ?link)[]
    		]
    	]
    ]
    
    The above code uses two named hooks to control what area's of the page get replaced, the first (tv) is where each of the TV lines will appear, the second (link) is used to make the Continue link disappear once there are no more items in the lines array.

    2. Timer based text updating:
    (set: $lines to (array: "TV text line 1", "TV text line 2", "TV text line 3", ""))
    
    |tv>[(print: $lines.shift())]
    
    (live: 5s)[
    	(replace: ?tv)[(print: $lines.shift())]
    	(if: $lines's length is 0)[
    		(stop:)
    	]
    ]
    
    The above code uses the (live: ) macro to create a timer that fires and updates the tv area every five seconds until the are no more items in the lines array. Note that the last item in the lines array is an empty string "", this is used to clear out the tv named hook.

    note: I have used indents and extra line-breaks in both of the above examples to make them more readable, these indents and extra line-breaks can be safely removed.
Sign In or Register to comment.