Sugarcube Help: Timed Remove for a <span id=

Twine Version: 2.3.7
Story Format: SugarCube 2.31.1

I get these errors with the code below. Would think Remove could refer to the same passage it’s in when there’s a Timed delay.
The other error is about the order I’m putting these in. Please help, I’m new and just want it to work :slight_smile:

Error: <>: no elements matched the selector
Error: child tag <> was found outside of a call to its parent macro <>

<<timed 4s>>
“WORDS WORDS WORDS WORDS.”
<<remove “#1”>>
<<next 3s>>
Fast Forwarding.

<<next 1s>><<remove “#2”>>

You need to close the <<timed>> macro by placing the code <</timed>> at the end.

In some cases you’ll have problems with element IDs that start with a number, so should probably change things like id="1" to something like id="e1" instead, and then the <<remove>> would need be done like this: <<remove "#e1">>

Additionally, as Chapel said, you’ll need to add a <</timed>> at the end.

If that doesn’t work, then there may be some error in the code elsewhere in that passage.

Hope that helps! :slight_smile:

P.S. This forum screws up code in a few cases. You’ll need to wrap any code within a “preformatted text” block (use the </> button) to prevent it from eating the contents of any SugarCube macros (so you’ll see <<remove>> instead of <>) and to keep it from changing standard double-quotes to fancy double-quotes.

Thanks, all! This isn’t my first open source community forum question-asking, and you guys are even more helpful than the Arduino folks!
Below, I’ve posted the whole, broken thing, just replaced the narrative with ‘Some Words’
Thanks again for helping with this, I’ve really rat-holed but the documentation’s not as good as you guys, clearly!

<span style='font-family: courier'><span id="e1">
Some words
</span><span id="e2"><<timed 4s>>
Some words</span><<remove "#e1">>
<<next 3s>><span id="e3">
Fast Forwarding.</span>
<<next 1s>><<remove "#e2">>
.Some words..
<<next 2s>><<remove "#e3">><span id="e4">
Fast Forwarding.
<<next 4s>><<remove "#e4">><span id="e5">
Some words
<<next 2s>><<remove "#e5">><span id="e6">
Some words
<<next 2s>><<remove "#e6">><span id="e7">
Some words
<<next 2s>><<remove "#e7">><span id="e8">
Some words.<<next 3s>>
<<button "Continue " <<script>><<print>>Some words <<timed 1s>>Some words<<next 1s>>Some words<<next 1s>>Some words.<<next 1s>> <</print>><</button>>
<</timed>>

OK, now I see the problem.

You started a <span>, then started a <<timed>> macro, and then you tried to end that <span> within that <<timed>> macro.

If you start X, and then start Y, you then must end Y before you can end X. They can’t cross over each other like that.

Also, you started <span>s e2 through e8, plus the very first <span>, but never closed any of them.

This is why indenting your code whenever you start a group, and unindenting when you end that group, is highly recommended when writing code. It makes it much harder to make that mistake.

Also, your <<button>> is missing the “>>” part, you have unnecessary <<script>> and <<print>> macros, and the <<print>> macro doesn’t have a closing <</print>> tag.

Here’s my best guess at the corrected code, with indentation:

<span style='font-family: courier'>
	<span id="e1">\
		Some words
	</span>\
	<<timed 4s>>\
		<span id="e2">\
			Some words.
		</span>\
		<<remove "#e1">>\
	<<next 3s>>\
		<span id="e3">\
			Fast Forwarding.
		</span>\
	<<next 1s>>\
		<<remove "#e2">>\
		.Some words..
	<<next 2s>>\
		<<remove "#e3">>\
		<span id="e4">\
			Fast Forwarding.
		</span>\
	<<next 4s>>\
		<<remove "#e4">>\
		<span id="e5">\
			Some words 1
		</span>\
	<<next 2s>>\
		<<remove "#e5">>\
		<span id="e6">\
			Some words 2
		</span>\
	<<next 2s>>\
		<<remove "#e6">>\
		<span id="e7">\
			Some words 3
		</span>\
	<<next 2s>>\
		<<remove "#e7">>\
		<span id="e8">\
			Some words.
		</span>\
	<<next 3s>>\
		<<button "Continue">>
			<<append "#e9">>\
				Some words
			<</append>>
			<<timed 1s>>
				<<append "#e9">>\
					Some words
				<</append>>
			<<next 1s>>
				<<append "#e9">>\
					Some words
				<</append>>
			<<next 1s>>
				<<append "#e9">>\
					Some words.
				<</append>>
			<</timed>>
		<</button>>
	<</timed>>\
	<span id="e9">\
	</span>
</span>

I added a few minor changes (such as the numbers after “Some words”) so that you could see that the text changed. Also, I had to guess a little bit about what you were trying to do with the <<button>> code. Hopefully I got all of that more-or-less correct.

The "\"s that you see at the end of lines are to prevent line breaks at that point. They make it easier to do indentation in your code.

Speaking of indentation, you should see there how, each time you start another group, you indent, and then unindent when the group is closed. Each set of consecutive lines of code at the same indentation level or higher, helps group that code within the parent set. So, for example, all of the lines indented one further level in after a <<next 2s>> line would be executed after that two second wait finishes, up to where the code unindents, which represents the end of that group of code.

Please let me know if you need any help understanding what any of that does or how it’s working if you can’t figure it out yourself by playing around with the code and reading the relevant parts of the SugarCube documentation.

Have fun! :smiley:

Thanks!