Howdy, Stranger!

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

Selecting links (not clicking through)

Sugarcube 2.12

Further to my recent thread about a new type of Twine game, I understand it's possible to 'select' a passage link (rather than having the link take you to another passage) so that a sub menu can be used to interact with the selected link.

I'm a long way from getting this idea off the ground, but I suppose I have to start somewhere and would like to ask how this is done?

Comments

  • edited December 2016
    I dunno, but maybe toggleclass? I am currently using it as a way to 'open' a small blurb of information, but links would work inside it. It acts as a link, that opens up a small box, depending on how you define the CSS.
    @
    

    @'s formatted this way specifically to make it appear to be an actual box, otherwise, it oddly just starts to create a container, but never quite 'finishes' it for some reason.

    The .inventory is a CSS selector you put in the Stylesheet Section, defining how the 'Inventory' Screen would look like. The CSS example are ripped from my own game.
    	
    .hide {
    		display: none;
    }
    
    .inventory {
    	padding: 5px;
    	border: 1px solid #00A;
    	background: #003;
    	color: #CCD;
    }
    

    The Inventory CSS mainly makes it a darkish blue bg with a border around it to distinguish from the standard Sugarcube BG and looks.

    I'm sure this probably isn't what you're looking for, but it IS another way to show information then hide it if you need to.

    (shrugs) :) Hope you can use it. I'm not 100% sure if the .hide CSS code is actually necessary or not.
  • Thanks, Gryph. I'll go and have a play around. I'm okay(ish) with css so might be able to get it looking more to my liking.
  • edited December 2016
    I quite like the way this works (and looks now that I've removed all the styling), but I can't figure out how to get the text which is triggered when you click the link, as links which in turn give a response.

    When the player clicks on chest, I want three options to show up examine / take / open

    When they are pressed I want another response relative to which they clicked.

    This is what I have but I get an error about no matching selector when I click either of the three options.
    @
    
  • edited December 2016
    Well this version doesn't produce errors, but neither does it work as desired. In this version the second and third options only appear when they click the previous.
    @
    
  • edited December 2016
    Finally!!!
    @
    
    Okay, so this is what I was trying to do, but now that I have, I would like each of the responses to be replaced by the other.

    So, the player clicks Chest and below this appears:
    examine / open / take
    
    So they click examine and below it appears [the objects description]

    But then when they click open, I'd like the objects description to be replaced with the open response, instead of it just appearing below the last response.
  • edited December 2016
    I see kinda what you mean. It sorta 'spawns' the next part. Let me see if I can work on it or something. I do think it is possible. I'm still not quite sure how yet. Maybe someone who's more expert on the toggleclass can help. I've only been using it for a little bit.


  • edited December 2016
    Just to clarify, this would be the ideal behaviour of object interaction (assuming chest has been clicked in the first instance:
    Room description, bla de bla de bla...
    There's a chest lying in the centre of the room.
    
    examine / open / take
    
    Then the player clicks examine and we get:
    Room description, bla de bla de bla...
    There's a chest lying in the centre of the room.
    
    examine / open / take
    It's a large treasure chest with a hinged lid.
    
    Then they click open and we get:
    Room description, bla de bla de bla...
    There's a chest lying in the centre of the room.
    
    examine / open / take
    It's locked.
    
    Where it's locked has replaced It's a large treasure chest with a hinged lid.

    Ideally, clicking chest would toggle the three options on and off.
  • edited December 2016
    Jud_Casper wrote: »
    Finally!!!
    @
    
    Okay, so this is what I was trying to do, but now that I have, I would like each of the responses to be replaced by the other.

    So, the player clicks Chest and below this appears:
    examine / open / take
    
    So they click examine and below it appears [the objects description]

    But then when they click open, I'd like the objects description to be replaced with the open response, instead of it just appearing below the last response.

    I'm still checking. And congrats on getting it to work - but I am trying to see if I can't figure out how to replace your initial text once you click on it. All I can think of is <<replace>> macro but I'm trying to make it work somehow. It's 'treating' those actions as individual actions. But I'm not sure how to put it in 'one window' so to speak.

    Maybe @TheMadExile could help? I keep thinking we should be using <<replace>> or <<linkappend>> and I've been looking at the documentation as well. <<linkreplace>> isn't a good idea since it's a one-time link. Anyway.
  • It's sorta frustrating me too. lol. And I'm not even using this for my project - yet :)
  • edited December 2016
    Unless you plan on only ever having one item per "room", you'll either need to use IDs or injection. If you rely on classes alone, you'll trigger the actions for every item in the room.

    For an example of using an ID, something like the following should do what you need:
    @
    </div>
    
    NOTE: I used a <div> for the chest action wrapper, since the custom styles markup cannot be nested.
  • edited December 2016
    That works perfectly! Thank you.

    I tried to have two objects but with the links in the same sentence. I got myself into a right mess and couldn't do it. Is it even possible?

    As in:
    There's a chest and a sword here.
  • That's why you need to either use separate IDs with each set of actions or inject each set of actions into a singular action area. I'll show examples of both this time.

    Both examples assume that only one set of actions should be shown at a time.

    EXAMPLE 1: Using separate IDs with each set of actions
    @
    </div>
    


    EXAMPLE 2: Injecting each set of actions into a single action area
    @
    \<</replace>>
    <</link>>
    \ here.
    <div id="items"></div>
    
  • edited December 2016
    A very basic example of two items.

    edit: removed because it was similar to one of TME's

    ... the above has a number of issues:

    1. Both of the action lists can be visible at the same time and when they are it is had to distinguish which list belongs to which item. There are many ways to solve this depending on exactly how you want the result to look.

    eg. should the action lists appear near the related item, should all actions appear in exactly the same place thus over writing any other list, should the list identify the related item, etc.....

    2. The above implementation does not scale very well for a number of reasons.

    eg. the link code needs to be copied to everywhere in the current passage the related item is mentioned; the link and display code needs to be copied to each passage the related item is mentioned in; etc...

    I believe a more ideal solution would globally define each of the items and their related actions/outcomes, and then use generic macros to display the both the item selection link and the related action links, as well as displaying any outcomes from using an action.

    A very basic example of an item definition.
    <<set $items to {}>>
    <<set $items["chest"] to {
    	"name": "chest",
    	"examine": "It's a large treausre chest.",
    	"open": "It's locked.",
    	"take": "It's too heavy."
    }>>
    
    note: the above example could also be written in Javascript, and the implementation of the "open" action should really be a block of code that first checks if the item can be opened (eg. you have a key) then generate the relevant String outcome.
  • edited December 2016
    Thank you both for your solutions.

    @TheMadExile - I think these options work well personally (although the toggle feature doesn't function in the revised versions) and I think any confusion as to what object you're 'examining' could be alleviated by having the 'active' object highlighted.

    @greyelf I very much like the idea of globally defining the objects all in one place (much like you do when caching audio), but my knowledge base won't allow me to move on from your idea on my own.

    I understand (I think) that I'd create an invisible passage (let's cal lit objects) and then use the above block of code for each object in the game. But what I would then need to do in the passages themselves in order to call this function is very much beyond me.
  • edited December 2016
    Jud_Casper wrote: »
    @TheMadExile - I think these options work well personally (although the toggle feature doesn't function in the revised versions) and I think any confusion as to what object you're 'examining' could be alleviated by having the 'active' object highlighted.
    Hmm. I forgot about that. It would be difficult, though not impossible, to add the ability to toggle the action sets off again to the injection version, so I'll skip that one for now.

    Here's an updated version using separate IDs which allows toggling the current action set off:
    @
    </div>
    
    CHANGES: I reworked both the chest and sword links so that only the items not being clicked are forcibly hidden, thus allowing the current item's action set to toggle on and off.
  • Marvellous work! Thank you.
  • Agreed. It's awesome. Now I feel like doing something like this in a project lol.
  • edited December 2016
    As @greyelf points out, its only downside is that this long script would need adding to each and every passage which contains an object - and we haven't even dealt with objects which contain objects (such as a box holding a key), which would mean the response to open would need a 'key' link with its own set of 'examine/take' functions.
  • edited December 2016
    Perhaps but it still has potential - and you can always maybe do synonyms for the actions, right? If you have different things you can open in one Passage? Like one is "open" the chest, and another is "crack open" a book? or even "read" a book instead of "examine", and so forth? I dunno.

    It could possibly work in combination with that method greyelf suggested, or an if condition which I know you hate, haha. (If chest is opened - get object, force the option to be erased somehow)
  • edited December 2016
    Yeah, it's a scary prospect when you consider all the things that need handling for this kind of thing (for instance, as you say, the description for 'open' on a box being different when it's contents have been taken).

    If the box initially contains a key, the open response will need to say so, but after the key is taken that description needs to change to reflect the fact.
  • edited December 2016
    Jud_Casper wrote: »
    Yeah, it's a scary prospect when you consider all the things that need handling for this kind of thing (for instance, as you say, the description for 'open' on a box being different when it's contents have been taken).

    If the box initially contains a key, the open response will need to say so, but after the key is taken that description needs to change to reflect the fact.

    Which could be maybe handled with an if condition.

    <<if $hasKey>>do the code for the description but for your new updated one<<else>>do the old description? and 'set' the $hasKey to True?<</if>>

    I dunno if that'd work - I haven't tested it. Argh. I guess it won't actually work. :/
Sign In or Register to comment.