It looks like you're new here. If you want to get involved, click one of these buttons!
<<set $myvar to 0>>in the StoryInit passage and then testing for it would be
<<if $myvar is 0>> do this stuff <<elseif $myvar is 1>> do this other stuff <<elseif $myvar is 2>> do this other stuff <<endif>>
<<else>>required in SugarCube, or is it ok to skip it, if not matching the conditions, where
<<else>>would be simply to "do nothing", as in:
<<if $myvar is 0>> do this stuff <<elseif $myvar is 1>> do this other stuff <<elseif $myvar is 2>> do this other stuff <<else>> <<endif>>
<<set $player = { name: "Player", maxHP: 50, HP: 50, maxMP: 10, MP: 10, AC: 6, attack: 1, damage: 1, speed: 10, gold: 10, XP: 0, levelUp: 100, level: 1 }>>
<<if $poisoned eq 1>> <<set $poisonDamage = Math.floor($player.maxHP * $monsterPoison) + Math.floor((Math.random()*3)+1)>> <<set $player.HP = $player.HP - $poisonDamage>> <<if $player.HP lte 0>> <<set $player.HP = 1>> <<endif>> You suffer <<print $poisonDamage>> damage from poison!<br><br> <<endif>> [[Attack!|Attack][$attackPower=1]]<br>
<<if $poisoned is 1>> <<set $poisonDamage = Math.floor($player.maxHP * $monsterPoison) + Math.floor((Math.random()*3)+1)>> <<set $player.HP to $player.HP - $poisonDamage>> <<if $player.HP <= 0>> <<set $player.HP to 1>> <<endif>> You suffer $poisonDamage damage from poison!<br><br> <<endif>> [[Attack!|Attack][$attackPower to 1]]<br>
Comments
As explained by the <<set>> macro documentation, the to operator is the equivalent of the equals-sign (=) operator, and both work for complex object values as well as standard values like String and integer.
Nothing, one is used word-based operators (eg. to and lte) and the other is using the equivalent Javascript maths-symbol-based operators (eg. = and <=).
The is is not the same as the equal-sign (=) or to operators, it is used for comparison where the other two are used for assignment.
One reason to use the word-based operators instead of maths-symbol-based ones is save yourself from the dreaded "single equals-sign vs double (or triple) equals-sign" problem that plagues both novice and experienced coders alike.
eg. you accidentally use an assignment operator when you wanted a comparison operator, and vise-versa.
If I understand you, where Sharpe had
eq is the same as is, but would not be accurate as
the = would be used for assignment, only.
as in would be the same as
where is also the same as
Let me know if I got it twisted up somewhere. Thanks, again!
The TwineScript eq operator is equivalent to the JavaScript == operator and is lazy equality. The neq operator has similar equivalence with the != operator.
The TwineScript is operator is equivalent to the JavaScript === operator and is strict equality. The isnot operator has similar equivalence with the !== operator.
The difference between lazy and strict equality is that lazy equality attempts type coercion when comparing values of dissimilar types while strict equality does not.
For example, say you're attempting to compare the values 5 (number) and 5 (number):
Now, let's say you're attempting to compare the values 5 (number) and '5' (string):
PS: I generally recommend the is/isnot operators.
You know, I must visit that page on my hard drive 15 times a day and I guess I missed it somehow. Now, I know it is all in the macros section, it will be easy to check.
That does look as if it would be really easy to remember.
Thank you, both, for taking time to answer my questions and explain so clearly. I already have over 70 passages and don't want to have to go back and fix stuff when there are 150.