Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Checkboxes (Sugarcube)

I've run into a snag with checkboxes in Sugarcube. I've read the Sugarcube documentation on checkboxes, but while I thought I figured it out, I cannot get it to work,

Here is a simple example of what I would do in Sugarcane:

Which of the following items would you like to take on your adventure?
<<checkbox $backpack "Sword">>
<<checkbox $backpack "Axe">>
<<checkbox $backpack "Pie">>

<<button [[Pack Your Bag]]>>
If someone could tell me how I would adapt that example into Sugarcube it would be much appreciated.

Comments

  • There are a couple of problems with your example.

    1. The variable_name parameter: Because you can select more than one checkbox at the same time you need to give each one its own unique variable_name and as the documentation states it need to be quoted (eg. wrapped in quotes)

    2. The other two mandatory parameters: The 2nd and 3rd parameters are meant to indicate the values to store in the variable named when the checkbox is unchecked and checked.

    So your example should look something like the following:

    <<checkbox "$hasSword" false true>>
    <<checkbox "$hasAxe" false true>>
    <<checkbox "$hasPie" false true>>
  • Hi, thanks for replying.

    Just to clarify first, I understood my example was wrong, I was just doing it how I knew how to do it in Sugarcane.

    I'm still confused though and am having trouble getting this to work (sorry, this is probably really clear to others).
    1: When I try to display (edit: via the print function) the result on the next passage, I keep getting no results (either a blank or a 0 or a false). Is there a 'button' (I know that might not be the right word) associated with the checklist command like there is in Sugarcane?
    2: Is there no way to have the checklist modify a single variable like in Sugarcane? In my Sugarcane example I could click on sword and pie and on the next page just have a <<print $backpack>> to display the results (sword,pie).
    3:Is there any way to make the box appear without the word true or false? Is it possible to just make a box next to the word axe and if the player checks it axe becomes true?

    Thank you again.
  • RE: 1 -  SugarCube's checkbox is able to update the associated variable when you check/uncheck the box so you don't need a <<button>>

    RE: 2 - I don't believe SugarCube's checkbox supports this, at least I could not see that ability when looking at its source code.

    RE: 3 - SugarCube's check box does not display anything besides the box itself, it leaves the displaying of text to you.

    (note: the following uses TWEE notation, lines starting with two colons indicate a new passage, text on the same line as the two colons is the new passage's title.)

    :: Start
    /% Create the array to store the backpack contents in. %/
    <<set $backpack to []>>

    Add items to backpack
    Sword <<checkbox "$addSword" false true false>>
    Axe <<checkbox "$addAxe" false true false>>
    Pie <<checkbox "$addPie" false true false>>

    <<button [[Next Passage]]>>
    <<if $addSword>><<set $backpack.push("Sword")>><</if>>
    <<if $addAxe>><<set $backpack.push("Axe")>><</if>>
    <<if $addPie>><<set $backpack.push("Pie")>><</if>>
    <</button>>


    :: Next Passage
    The checkbox's selected:
    Sword: <<print $addSword>>
    Axe: <<print $addAxe>>
    Pie: <<print $addPie>>

    Backpack contains <<print $backpack>>
  • Thank you very much I have it working now, I really appreciate the help.
  • greyelf wrote:

    Sword <<checkbox "$addSword" false true false>>
    Axe <<checkbox "$addAxe" false true false>>
    Pie <<checkbox "$addPie" false true false>>


    There are one too many arguments to those &lt;&lt;checkbox&gt;&gt; calls, the final boolean is erroneous and is simply being ignored.  The above should be:

    Sword <<checkbox "$addSword" false true>>
    Axe <<checkbox "$addAxe" false true>>
    Pie <<checkbox "$addPie" false true>>
    The, optional, fourth argument is the checked keyword.


    I'll also note that SugarCube's input macros allow complex $variable assignments, so, if a generic object were used, you could also do something like this:

    <<checkbox "$packed.sword" false true>> Sword
    <<checkbox "$packed.axe" false true>> Axe
    <<checkbox "$packed.pie" false true>> Pie
    Thereby assigning directly to the properties of $packed.
Sign In or Register to comment.