Hello,
I want to change the color of something I write based on a story variable.
For example I could use this:
<<if $variable lt 2>><span style="color:blue">TEXT</span><<else>><span style="color:red">TEXT</span><</if>>
But I want to change the color of the text in A LOT of passages and using the above would mean a lot of repetition.
Is there some kind of Javascript with which I could do the if-check on every load of a passage and modify a CSS style element?
Comments
Based on the syntax of you example we can assume you are using one of the SugarCube versions but without further information we can't guess which one, and it could make a difference in the coding of any solutions given.
Besides @mykael excellent suggestion of using a custom macro/widget to abstract the code that determines which style to display the text in, you could also use <<addclass>>/<<removeclass>> macros to conditionally add a CSS class name to the current page**@ based markup to apply it.
eg. Say I have a $playerEmotion variable that represents the player's emotional state (blue=sad / red=angry) and that the variable's values are "sad" / "angry".
** which HTML element to target can depend on the version of SugarCube you are using.