Howdy, Stranger!

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

Questions about Sugarcube 2x

I'm using sugarcube 2x in Twine 1.4

I want to know if it's possible to have a link display a list of variables of a certain class.

Like for example I have this link called 'move' that will give you a list of rooms you can go to, and in order to display all of the links it searches for variables that have the class 'move' assigned to them.

I'm sorry I can't give any examples in code, I can't write any off the top of my head.

Comments

  • This needs a better explanation, because it's not making a whole lot of sense to me as-is.
  • Could you supply an example of one of your variables that has a class of 'move' assigned to it?
  • <<set $outside to "[[Outside]]">>
    <<addclass $outside "fromRoomY" >>
    
    Upon writing this code and testing it for myself I realized that the second line of code doesn't work and returns an error.
    If I may reiterate my question, how can you assign a class to a $variable?
  • edited September 2015
    You cannot. The <<addclass>> macro is for adding classes to HTML elements. Honestly, I'm surprised this is even a question.

    Why are you trying to add classes to story variables in the first place? If you know which variables need to be flagged in some way to denote they should included in your list of moves, then you already know which ones you need to include in said list. I'm not seeing the point in what you're trying to do.

    Explaining what you're trying to accomplish may be helpful. What's the end result you wish to achieve?
  • Right... sorry. I'm a noob.

    I'm trying to make a game that plays similarly to a visual novel called Snatcher.
    images?q=tbn:ANd9GcQ42mmBcSUJWBNGqwJQt3_KaKQlhcJg8Alq4-QxbMBkEYMuTB6V

    Pressing one of the options, move, look, etc would give you a list of other links (where to move, where to look), and these lists would change depending on the room.
    (I know I could accomplish this just by having a long series of ifs, but I wanted to try something else).
  • You could do them as collapsible menus or something. For example:
    Image, text, whatever.
    
    <<click "MOVE">>
    <<toggleclass "#options-move" "show">>
    <</click>><span id="options-move"> &gt; <<nobr>>
    [[West|Corridor B]],
    [[East|Carridor A]],
    [[Down the hole]]
    <</nobr>></span>
    \
    <<click "LOOK">>
    <<toggleclass "#options-look" "show">>
    <</click>><span id="options-look"> &gt; <<nobr>>
    [[Look at potted plant]],
    [[Pick up the Bloody Card®]]
    <</nobr>></span>
    \
    [[A SINGLE OPTION ITEM]]
    
    And the attendant CSS:
    /*
    	Styles to hide/show the options lists.
    */
    [id|="options"] {
    	display: none;
    }
    [id|="options"].show {
    	display: inline;
    }
    

    That's a fairly simple example, but you should get the idea. You could change how the options are presented and shown for extra flair. Additionally, the <<click>> macros could be turned into widgets to make things more tidy and reusable.
  • It works!
    Thank you for your time. I'll let you know if I have anymore questions.
    Thanks again!
Sign In or Register to comment.