I need to change a Java script I download, but I do not know how

Twine Version: Latest

So, I downlaoded the Custom Macro “Speech Box System”
This Macro works using Java and CSS. I know how to edit CSS, but Java eludes me completely. The thing is, this macro lets me create a character and assing an image to show its avatar. I want to do that, but I need the avatar to change based on a Twine variable ($mood)
I know how to write the code in Twine, that is not the problem. But the .js is written in such a way, that the avatar section only works for images, so it does not allow a variable, even if the variable == an img.
Can someone tell me what is it that I have to change in the .js? Thanks!

I don’t wanna be that guy, but… Java and JavaScript are two completely different programming languages.

I don’t think you need to change the source code. After reading the documentation you linked, why don’t you create different character macros for each mood, for example, Lisa_Sad, Lisa_Happy, Lisa_Surprised, ec, and then use the appropriate character mood in you own code.

Would that be a solution?


The thing is, that would work if I wanted the dialogue to be different depending on the mood. But I don’t. I want the avatar to be a sort of “clue” for the player to understand the mood the character currently has. If I were to create a character for each mood, I would need to copy paste each dialogue line six times, one for each mood, inside a big if and ifelse macro, leaving me with huge passages and strigs even for the smallest interaction.

Not necessarily. You could do something like this:

<<if $mood == "happy">>
    <<set _img to "images/lisa_happy.jpg">>
    <<set _img to "images/lisa_sad.jpg">>

<<say 'Lisa' _img>>Hey there!<</say>>

If you consistently name all your images name_mood or something equivalent, you could even do all this in one line, like this:

<<say 'Lisa' `'images/lisa_'+$mood+'.jpg'`>>Hey there!<</say>>

Or, if you want to use the same syntax as in the examples, you could use a widget instead of the <<character>> macro. Create a new passage, tag it widget (and optionally nobr), with this code:

<<widget lisa container>>
    <<say 'Lisa' `'images/lisa_'+$mood+'.jpg'`>>_contents<</say>>

Then you can use this syntax as normal:

<<lisa>>Hey there!<</lisa>>

That was it! thank you so much :+1: