Twine version : 2.12.0.0 / SugarCube 2.37.3
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
I am creating a template for my future IF (where each choice is supposed to have an effect on the story). To cut down the number of passages, I decided to mark each choice link with a $variable, and use IF statements to check with parts of the story should be visible at what time. Then to cut down the number of variables, I decided to only have one $variable per passage for choice links, and then add the link choices beneath it using Bitwise Flags (after learning such things existed). (If I can get them to work, I’ll probably use them elsewhere too, but right now, I want to focus on this.) …based on the information I have, Bitwise Flags should work on SugarCube… ?
I may know more than the average person, but I am far from being proficient in coding (or using Twine and SucarCube), at best, I merely dabble…and right now I am at my wits end.
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
“StoryInit” Passage
Question : Can the “Value option” name be the same for multiple Flags? Or do they have to be unique?
So is this ok?
<<set $passage111name = 0>>
<<set setup.Choice01 = Math.pow(2, 0)>>
<<set setup.Choice02 = Math.pow(2, 1)>>
<<set setup.Choice03 = Math.pow(2, 2)>>
<<set setup.Choice04 = Math.pow(2, 3)>>
<<set $passage222name = 0>>
<<set setup.Choice01 = Math.pow(2, 0)>>
<<set setup.Choice02 = Math.pow(2, 1)>>
<<set setup.Choice03 = Math.pow(2, 2)>>
<<set setup.Choice04 = Math.pow(2, 3)>>
Or is this how it is suppose to be?
<<set $passage111name = 0>>
<<set setup.P111Choice01 = Math.pow(2, 0)>>
<<set setup.P111Choice02 = Math.pow(2, 1)>>
<<set setup.P111Choice03 = Math.pow(2, 2)>>
<<set setup.P111Choice04 = Math.pow(2, 3)>>
<<set $passage222name =0>>
<<set setup.P222Choice01 = Math.pow(2, 0>>
<<set setup.P222Choice02 = Math.pow(2, 1)>>
<<set setup.P222Choice03 = Math.pow(2, 2)>>
<<set setup.P222Choice04 = Math.pow(2, 3)>>
Question : Just to make sure, that is how the code is supposed to look, right?
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Passage containing the Flag
<<link "Choice01" "passage222name">><<set $passage111name |= setup.Choice01>><</link>>
<<link "Choice02" "passage222name">><<set $passage111name |= setup.Choice02>><</link>>
<<link "Choice03" "passage222name">><<set $passage111name |= setup.Choice03>><</link>>
<<link "Choice04" "passage222name">><<set $passage111name |= setup.Choice04>><</link>>
That is how it is suppose to look like when using with a link…I think.
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Question : How to make it (and other variables) work with ToggleLink (widget) ?
Passage : toggle-link Tags: widget nobr
<<widget "toggleLink">>
<<if ndef _tlink>>
<<set _tlink = 1>>
<<else>>
<<set _tlink++>>
<</if>>
<<set _linkStr = "$('.togglelink[id!=\\'tlink" + _tlink + "\\']')">>
<span @id="'tlink' + _tlink" class="togglelink"
@onmouseenter="_linkStr + '.addClass(\'disabled\')'"
@onmouseleave="_linkStr + '.removeClass(\'disabled\')'">
<<link $args[0] $args[1]>><</link>>
</span>
<</widget>>
Passage containing the Flag
<<toggleLink "Choice 1" "Chapter 1">>
<<toggleLink "Choice 2" "Chapter 1">>
<<toggleLink "Choice 3" "Chapter 1">>
<<toggleLink "Choice 4" "Chapter 1">>
It doesn’t have <> so where I am suppose to put the <<set $variables>> ? Can it even be done ?
This is really not “a must”…but I do kinda fancy the effect it has on the choice links. It would be nice to get the IF not only working smoothly but also looking good.
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Passage checking for the Flag
When using the regular choice links, I can get this far :
<<if ($passage111name & setup.Choice01)>>
Flag 1 is set.
<<elseif ($passage111name & setup.Choice02)>>
Flag 2 is set.
<<elseif ($passage111name & setup.Choice03)>>
Flag 3 is set.
<<elseif ($passage111name & setup.Choice04)>>
Flag 4 is set.
<</if>>
: and it works. So, I assume it is correct…?
But when I try to check for multiple Flags, it stops working…
<<if (($passage111name & setup.Choice01) & (($passage222name & setup.Choice01))>>
Flag 111 choice01 and Flag 222 choice01
<<elseif (($passage111name & setup.Choice02) & (($passage222name & setup.Choice02))>>
Flag 111 choice02 and Flag 222 choice02
<<elseif (($passage111name & setup.Choice03) & (($passage222name & setup.Choice03))>>
Flag 111 choice03 and Flag 222 choice03
<<elseif (($passage111name & setup.Choice04) & (($passage222name & setup.Choice04))>>
Flag 111 choice04 and Flag 222 choice04
<</if>>
…regardless of which StoryInit version I use…
<<if (($passage111name & setup.P111Choice01) & (($passage222name & setup.P222Choice01))>>
Flag 111 choice01 and Flag 222 choice01
<<elseif (($passage111name & setup.P111Choice02) & (($passage222name & setup.P222Choice02))>>
Flag 111 choice02 and Flag 222 choice02
<<elseif (($passage111name & setup.P111Choice03) & (($passage222name & setup.P222Choice03))>>
Flag 111 choice03 and Flag 222 choice03
<<elseif (($passage111name & setup.P111Choice04) & (($passage222name & setup.P222Choice04))>>
Flag 111 choice04 and Flag 222 choice04
<</if>>
…and regardless of whether I use the “&” or “and” between the two $variables :
<<if (($passage111name & setup.P111Choice01) & ($passage222name & setup.P222Choice01))>>
<<if (($passage111name & setup.P111Choice01) and ($passage222name & setup.P222Choice01))>>
Any help and / or clarification is welcomed with open arms!
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~