0 votes
by (2.4k points)
edited by

Hey there, hope you're having a great morning!

I'm faced with a situation I do not understand, "eq" is not working the way I thought it would with me. 
Here's what I want to do : 

''_nameActuel'' : <<if  _nameActuel eq $sName>>@@color:pink; _message @@ <<else>> _message <</if>> <br/> 

This doesn't work ! Whereas it seems to me that $sName is equal to _nameActuel ! 

For proof, if I write : 

"_nameActuel", "$sName"
''_nameActuel'' : <<if _nameActuel eq $sName>>@@color:pink; _message @@ <<else>> _message <</if>> <br/> 

It gives me : 

"Melody","Melody" Melody : (message) 

But the message won't turn pink ! Whereas if I write "neq" instead, it does become pink. Which means that "Melody" and "Melody" are not equal, but why ? Is it because one is a _ variable, and the other one a $ variable ?

And why do you sometimes have to use _variables ? 

(This is all within a widget, _nameActuel has been declared in the widget whereas $sName has been declared elsewhere)

Thanks for your answer ! 

2 Answers

+2 votes
by (68.6k points)
selected by
Best answer

It isn't working because you're quoting the variables in the <<chat>> invocation, which you almost never want to do.  Your example invocation also looks like it has too many lines of chat in a couple of cases (though perhaps not, I didn't look at the widget's code too much) and is missing a space between two of the arguments.

Arguments in all macro invocations (including widgets) are separated by whitespace, but that whitespace isn't limited to simple spaces, so I'd suggest using line breaks to separate each round of dialog in your <<chat>> invocations.

Try something like the following:

<<chat $name $sName
    $sName "Hey bro?" "I've heard you were coming home for the summer?"
    $name  "Yes"
    $sName "That's amazing! And you didn't tell me? :("
    $name  "..." "You know why."
    $sName "What?!"

by (2.4k points)
Wow that's amazing, you made it work.
I had no idea you could separate arguments within an invocation like this.
Thanks a lot !
0 votes
by (8.9k points)
edited by

What versions are you using?  Your code works in Twine 2.1.3, Sugarcube 2.18.0.

<<set _nameActuel to "Melody">>
<<set $sName to "Melody">>

''_nameActuel'' : <<if  _nameActuel eq $sName>>@@color:pink; _message @@ <<else>> _message <</if>> <br/> 

<<set _nameActuel to "Charlie">>

''_nameActuel'' : <<if  _nameActuel eq $sName>>@@color:pink; _message @@ <<else>> _message <</if>> <br/> 

That prints _message in pink when _nameActuel is set to "Melody", and in the default colour when it's set to "Charlie".

by (2.4k points)

I'm using the same version as you are, and still I can't see what I'm doing wrong with my code. 

Here is the whole thing :  (I'm sorry, for a reason I ignore I can't find the code format to post)

The beginning : 

Hello there. To maximize your experience, you may enter a name : 

<<textbox "$name" "James">>

You may as well enter the name of your friend, and the name of your best friend :

Friend: <<textbox "$sName" "Bob">>
Best friend : <<textbox "$bfName" "Sarah">>


The widget :

<<widget 'chat'>>


<<set _name to $args.shift()>>

<<set _name2 to $args.shift()>> 

<<set _nameActuel to _name>>

<<set _i to 0>>


<<timed 2s>>

<<replace '#Connect'>>

@@color:green;''Connected !''@@ 



<<timed 4s>>

<<remove '#Connect'>>


<<repeat 4s>>

<<if $args[_i] eq _name>>

<<set _nameActuel to _name>> 

<<set _i++>>

<<elseif $args[_i] eq _name2>> 

<<set _nameActuel to _name2>>

<<set _i++>>


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

@@#typing; <<if _nameActuel neq _name>>''_nameActuel'' is<<else>> ''You'' are <</if>> writing@@ 

<<timed `either("1","1.5","2","2.5","3") + "s"`>> 

<<remove '#typing'>> 


''_nameActuel'' : <<if "$sName" eq "_nameActuel">> @@color:pink; _message @@ <<else>> _message <</if>> <br/> 


<<if _i eq ($args.length - 1)>>



<<set _i++>>




And the widget application : 

<<chat '$name' '$sName' '$sName' 'Hey bro?' 'I\'ve heard you were coming home for the summer?' '$name' 'Yes' '$sName''That\'s amazing! And you didn\'t tell me? :(' '$name' '...' 'You know why.' '$sName' 'What?!'>>

Here's what this code gives me : 

"Bob","Bob" Bob : Hey bro? 
"Bob","Bob" Bob : I've heard you were coming home for the summer? 
"James","Bob" James : Yes 
"Bob","Bob" Bob : That's amazing! And you didn't tell me? :( 
"James","Bob" James : ... 
"James","Bob" James : You know why. 
"Bob","Bob" Bob : What?! 

I let the " "$sName" and the "_nameActuel" before the actual tchat lines to help and we can see "Bob" is equal to "Bob" more than once ! Yet it's not considered as such ? (Text does not appear pink even once ?) 

I'm lost on this. Thanks for the help !