0 votes
by (160 points)

I'm using sugarcube 2,21 on Twine 2 and i'm relatively new to the twine story making, i'm building a story with 3 difficulties settings which in fact change how the story is seen, easy is more image and less text, normal is image and text at equal ratio and hard is only text. Fact is not easy or hard at all since its all the same difficulty, just more reading or not. Regardless I'm using a radiobutton to define 3 types of $Mode 1, 2 and 3 where each is easy, normal and hard respectively and $Mode the game option setting.

But once I try to use these values with If it always tell me the value is not defined or if i place it on brackets no effect whatsoeverhappens, Some help sure is appreciated or at least a place where I can look to it properly, maybe i'm dumb and sugarcube library has the answer but i cant seen to find it.

here is how i coded any insight is welcomed

<<set $Mode=["1", "2", "3"]>>
<<radiobutton "$Mode" "1">><span style="color:#008000">''Easy''</span>. 
<<radiobutton "$Mode" "2"checked>><span style="color:#FFFF00;">''Normal''</span>. 
<<radiobutton "$Mode" "3">><span style="color:#FF0000;">''Hard''</span>.  

<<nobr>>
<<if $Mode == 1>>
<<display [[Easy]]>>  
<<elseif $Mode == 2>>
<<display [[Normal]]>>
<<else $Mode == 3>>
<<display [[hard]]>>
<</if>>
<</nobr>>

this is the current code i tried variations on the if with other values like eq, is, to, and. also tried $Mode.1,$Mode.2, $Mode.3 on the if variable. tried changind from display to print, to link and all sort of commands

I'm kind of lost on what i need to do to make it work so any help is welcome

2 Answers

+1 vote
by (154k points)
selected by
 
Best answer

Please don't include information about the Story Format being used within the Question Title, it just makes it longer than necessary. There are a couple of issues with your example:

1. You have a number of Data-Type miss-matches.

You are initialising the $Mode story variable as an Array, you have the <<radiobutton>> macros are assigning String values, and you are checking for Numeric (Integer) values in the conditional expressions of your <<if>> related macro calls.

I suggest changing each of those three things to use the same data-type, a Numeric (Integer) value perhaps.

2. The 2nd <<radiobutton>> macro is malformed.

You should using a Space character to separate the checked keyword from the checkedValue value.

3. Using the value assigned by the <<radiobutton> macros within the same Passage it's set in.

The contents of the whole Passage is processed before it is show to the Reader, this means that your <<if>> related macros are processed before the Reader has had a chance to select one of the <<radiobuttons>>.

The standard way to over come this issue is to place the <<if>> related macros on the next Passage shown to the Reader.

4. You are passing a conditional expression to your <<else>> macro, that macro doesn't accept a parameter.

5. You are using the deprecated <<display>> macro to display the contents of your Easy, Normal, and Hard passages.

You should be using the replacement <<include> macro instead.

The following is a slightly modifies version of your own example, it is written using TWEE Notation and consists of two Passages named Start and Result

:: Start
<<set $Mode to 2>>
<<radiobutton "$Mode" 1>><span style="color:#008000">''Easy''</span>. 
<<radiobutton "$Mode" 2 checked>><span style="color:#FFFF00;">''Normal''</span>.
<<radiobutton "$Mode" 3>><span style="color:#FF0000;">''Hard''</span>.  
[[Result]]

:: Result
<<nobr>>
<<if $Mode is 1>>
	<<include "Easy">>
<<elseif $Mode is 2>>
	<<include "Normal">>
<<else>>
	<<include "Hard">>
<</if>>
<</nobr>>

 

0 votes
by (38.6k points)

What greyelf says is correct, however I think you want code that looks a bit more like this:

<<radiobutton "_Mode" "Easy">><span style="color:#008000">''Easy''</span>. 
<<radiobutton "_Mode" "Normal" checked>><span style="color:#FFFF00;">''Normal''</span>.
<<radiobutton "_Mode" "Hard">><span style="color:#FF0000;">''Hard''</span>.

<<link "Begin">><<goto _Mode>><</link>>

That uses a temporary variable (one with an "_" in front of it) to store the mode.  However, if you need the value of Mode in later passages then you should change that to a story variable (one with a "$" in front of it).

Mode doesn't need to be initialized, because setting "checked" on one of the radiobuttons effectively does that already.

The <<link>> macro is used here, since the code inside of it only gets run when the user clicks on it, at which point Mode should have the value the user wants.

Also, the <<goto>> macro used above should be used with caution, since it will continue to execute any code after the <<goto>> is called (which probably won't be a problem in this case).

Hope that helps! smiley

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...