0 votes
by (2.4k points)

Hey there, I'm back ! 
I've asked for help a while ago and got great help from Chapel, yet I didn't have enough time so far to continue trying out stuff with SugarCube. 
Well, I've managed to do something, and obviously I'm having some issues I can't understand. 

So here's the thing, I've done a widget "chat" which manages to simulate a conversation. I enter 2 names (<<chat 'Roméo' 'Juliette'>> then enter who speaks first, what they say, then when I want the other one to talk I enter his name and do the same. (<<chat 'Roméo' 'Juliette' 'Roméo' 'You re amazing, Juliette' 'Juliette' 'Oh, thanks Roméo...' >>
Like this ! 

And this part has been working wonderfuly. 

But here's where I am having trouble with : I can't manage to print out "name is writing" and erase/replace it when the sentence is printed. 

Here's what I've tried : 

 

<<widget 'chat'>>
<<nobr>>
<<set _name to $args.shift()>>
<<set _name2 to $args.shift()>> 
<<set _nameActuel to _name>>
<<set _i to 0>>




<<repeat 2s>>

<<if $args[_i] eq _name>>
<<set _nameActuel to _name>> 
<<set _i++>>

<<elseif $args[_i] eq _name2>> 
<<set _nameActuel to _name2>>
<<set _i++>>

<</if>>

<<set _message to $args[_i]>> 

@@#typing; _nameActuel is writing.@@ <br/> 
 
<<timed 1s>> 
''_nameActuel'' : <<if _nameActuel eq 'Joris'>>@@color:red; _message @@ <<else>> _message <</if>> <br/>   
<</timed>>

<<remove '#typing'>>



<<set _i++>>
<</repeat>>


<</nobr>>
<</widget>>

 

This "almost" works, but I get the error "Error: <<remove>>: no elements matched the selector "#typing" ", 

Although the <<remove>> is obviously doing its job ? And I have no idea how to include <<br/>> in the @@#typing;@@ thing, it makes me an error as well ? 

Hopefuly I've been clear enough... I'm sorry if I wasn't, please let me know !

And thanks a lot for your help !
 

 

1 Answer

0 votes
by (63.7k points)
selected by
 
Best answer

I believe that the <<remove>> should be inside the <<timed>>, otherwise it would execute immediately, removing the #typing text before the player had a chance to see it.  Changing that will also resolve the reason you're seeing the error message, which is because you're attempting to remove the #typing element before it's on the page.

For example:

@@#typing;_nameActuel is writing.@@<br/> 
 
<<timed 1s>>
<<remove '#typing'>>
\''_nameActuel'' : <<if _nameActuel eq 'Joris'>>@@color:red;_message@@<<else>>_message<</if>><br/>   
<</timed>>

 

by (2.4k points)
Indeed that was it !
Thanks a lot !
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.
...