Problem with timing (SugarCube 2)

Good evening,

I ran into a problem with timing again. This passage:

<<set $letterArray to []>>
<<set _letters to "abcdefghijklmnopqstuvwxyzäöüß">>
<<for _i=0;_i<1000;_i++>>
	<<set _rnd to random(_letters.length)>>
	<<set _randomLetter to _letters.charAt(_rnd)>>
	<<set $letterArray.push(_randomLetter)>>				

	<<set $amount to 6>>
<<for _i=0;_i<$amount;_i++>>\
	<<set _pos to random($letterArray.length)>>
	<<set $letterArray[_pos] to '<span class="dot" id="dot-' + _i + '"><<link "●">><<replace "#dot-' + _i + '>>">><span class="black">●</span><</replace>><<audio "shoot" play>><<set _levelPoints+=10>><</link>></span>'>>

<<set _posToReplace to random($letterArray.length)>>
<<set $letterArray[_posToReplace] to '<span class="red" id="boom"><<link "●">><<audio "wrong" play>><</link>></span>'>>

<<for _i=0; _i<$letterArray.length; _i++>>
	<<print $letterArray[_i]>>

works fine when I open it directly in debug mode. But when I run the game and link to it, I get e.g.

<<replace>>: no elements matched the selector "#dot-2>>"

I understand it must be some kind of problem that “#dot-2” does not exist when is clicked. But why does it work in debug mode? Is there a way to fix this? I tried putting content into “PassageDone” passage, but no success.

Your quoting is messed up here:

...<<replace "#dot-' + _i + '>>">>...

That’s why the error is saying, “no elements matched the selector "#dot-2>>"”.

It should be:

...<<replace "#dot-' + _i + '">>...

Now it should try to match #dot-2 instead of #dot-2>>.

Enjoy! :slight_smile:

1 Like

Thank you!