I was wondering if you would be able to say have a random number and then if the number was say, 1 then add tag happy.
I tried using the following code but it came up with this error: "Error: <<if>>: assignment operator found within <<if>> clause (perhaps you meant to use an equality operator: ==, ===, eq, is), invalid: $random="1" add tag happy"
<<if $random="1" add tag happy>><</if>>
Also. Please use the code tag—it's C on the editor bar—when posting code or markup.
If you simply want to track a state, like being happy, then you should use a story variable.
If you're referring specifically to passage tags, then no. Passage tags should be considered immutable. That said, you may add classes easily enough.
For the moment, however, I'll assume you want to do the former.
There's so much wrong with your code that anything I say would likely sound like pedantry, so we'll skip right to code examples—though you should probably look over SugarCube's documentation, I'm assuming v2 for now; parts relevant to this discussion: variables, <<set>> macro, <<if>> macro, random() function.
The first thing you should do is initialize the story variable $happy in the StoryInit special passage—that's simply a passage by that name; see: Special Names for more information. For example, the following sets $happy initially to the boolean value false:
Later on, the following example checks to see if the value returned by random(1, 2) is the number 1 and, if so, sets $happy to the boolean value true: That could actually be simplified to the following—though perhaps that's a bit advanced for this discussion:
You may check the value of $happy in one of the following ways:
I'm sorry if that was unclear.
You can still use classes for this. Tags add classes you can use for styling as a part of what they do, but shouldn't be used dynamically. Classes can be used dynamically.
Then in CSS: