Howdy, Stranger!

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

Choices without nodes

edited January 2014 in Help! with 1.x
Hmm, I think it did as it's vanished.  Mth (I think) had posted some helpful examples about how to code up a 'fake choice' that didn't generate a new node using <if> and variables.  Any chance of getting it back, or did it get swept away with all of the crazy spam?  :-[

Edit: I updated the title of the post so it could be helpful in future as the original post was accidentally deleted.  Basically I am just looking on guidance on how to write passages which might have 'fake choices', a bit similar to the concept used in choicescript

Comments

  • Yes, the thread seems to be missing.

    Fortunately I still had the code in a file, since I tested it before posting. Here it is again:

    :: Start
    [[Have breakfast.|Breakfast]]

    :: Breakfast
    For breakfast I ate \
    <<if $breakfast>>\
    <<print $breakfast>>.

    [[Continue.|End]]
    <<else>>\
    [[cornflakes|Breakfast][$breakfast = "cornflakes"]], \
    [[toast|Breakfast][$breakfast = "toast"]], \
    or [[nothing|Breakfast][$breakfast = "nothing"]]? \
    <<endif>>

    :: End
    The end.
  • I apologize if I nicked your thread while deleting those 20+ pages of spam.  :-[

    We're working on things like spam mods and Anti-Spam Verification Questions right now so we don't have this problem again.

    Again, sorry.
  • Thanks both, no worries about deleting I kinda figured that was what had happened.  I've updated the first post to reflect the original one. 

    Mth, you mentioned using <<replace>> or using a <<div>> to achieve the same as above but without a transition...is it possible you could give me an example?  No worries if not, as the first example was helpful anyway, I think it was just for curiosity's sake.

    Thanks
  • bawpie wrote:

    Mth, you mentioned using <<replace>> or using a <<div>> to achieve the same as above but without a transition...is it possible you could give me an example?  No worries if not, as the first example was helpful anyway, I think it was just for curiosity's sake.


    This is the basic version:

    :: Start
    [[Have breakfast.|Breakfast]]

    :: Breakfast
    For breakfast I ate \
    <<nobr>><span id="breakfast">
    <<click "cornflakes">><<set $breakfast to "cornflakes">><<replace "#breakfast">><<display "Breakfast Chosen">><</replace>><</click>>,
    <<click "toast">><<set $breakfast to "toast">><<replace "#breakfast">><<display "Breakfast Chosen">><</replace>><</click>>, or
    <<click "nothing">><<set $breakfast to "nothing">><<replace "#breakfast">><<display "Breakfast Chosen">><</replace>><</click>>?
    </span><</nobr>>

    :: Breakfast Chosen
    <<print $breakfast>>.

    [[Continue.|End]]

    :: End
    The end.
    I tested it with SugarCube; I don't know if Leon's <<replace>> macro works exactly the same and whether his macros include <<click>> as well.

    In any case, the essential part is that <<replace>> takes a jQuery selector as its argument so it knows what HTML tag (more accurately, DOM node) to replace. The simplest form of selector is the ID, which looks as "#foo" in the selector and <span id="foo"> in the HTML.

    Since I don't like duplicated code, I put the click-and-replace mechanism in a widget:

    :: clickreplace [widget]
    <<widget clickreplace>>\
    <<click $args[2]>><<set state.active.variables[$args[1]] to $args[2]>><<replace $args[0]>><<display "Breakfast Chosen">><</replace>><</click>>\
    <</widget>>

    :: Start
    [[Have breakfast.|Breakfast]]

    :: Breakfast
    For breakfast I ate <span id="breakfast"><<clickreplace "#breakfast" "breakfast" "cornflakes">>, <<clickreplace "#breakfast" "breakfast" "toast">>, or <<clickreplace "#breakfast" "breakfast" "nothing">>?</span>

    :: Breakfast Chosen
    <<print $breakfast>>.

    [[Continue.|End]]

    :: End
    The end.
    This certainly requires SugarCube.
  • Thanks mth.  Whilst Leon has said that his replace macro is exactly the same as click in this thread, I'm not sure it can do that.  His revision macro certainly can, but it's very clumsy to write (or at least the way I've got it working is clumsy, there's probably a better way.  If I could incorporate the span part into the first block (which replaces the choices) then that'd be cool, but I'm not sure if it can do that or not?
    For breakfast I had <<nobr>>
    <<revision choice1>>
    <<revision choice2>>
    <<revision choice3>>
    <<revise choice1 "cornflakes">>,
    <<revise choice2 "toast">>,
    or <<revise choice3 "nothing">>?<br>
    <<endrevision>>
    <<endrevision>>
    <<endrevision>>

    <<revision choice1>><<becomes>>cornflakes. <br><br>
    They were a bit stale.<<endrevision>>

    <<revision choice2>><<becomes>>toast. <br><br>
    It was pretty nice actually.<<endrevision>>

    <<revision choice3>><<becomes>>nothing. <br><br>
    So now I'm super hungry.<<endrevision>>
    <<endnobr>>
    I know I could just bite the bullet and use twine the way it was built to reflect all the choices, but I have a lot of these fakechoices (I'm looking at porting over a choicescript project into twine) thrown in for flavour more than anything else, and I'd like to just look at the node map and get an idea where any really branching occurs.  Cyclinglink and replace also could do this, but they wouldn't show all the choices...which isn't necessarily a bad thing I guess? 

    Anyway, thanks for the help with this, it's really appreciated!
  • Without thinking about how to implement it, I think the desired syntax would be something like this:

    For breakfast I ate <<inlinechoice>>\
    <<option "cornflakes">>cornflakes. They were a bit stale.<</option>>, \
    <<option "toast">>toast. It was pretty nice actually.<</option>>, or \
    <<option "nothing">>nothing. I overslept and had to hurry.<</option>>?\
    <<append>>

    [[Continue.|End]]<</append>><</inlinechoice>>
    Here the surrounding <<inlinechoice>> macro will insert a <span> element to be replaced. The initial text is formed by using the text contained in the <<inlinechoice>> and the option arguments converted to links. If an option link is clicked, the <span> contents are replaced by the selected <<option>> contents followed by the <<append>> contents.

    For implementing this, only a custom macro in JavaScript would do it, I think. Widgets cannot have any contents, so they would not be an option, even if you were using SugarCube.
  • I've found a code on codepen (original link) which I've tweaked, however, it only seems to work with images.  Not sure what I need to change to get it to accept links only...my version is here if anyone is interested in helping me figure it out. :) 

    Edit: Getting a bit further with trial and error. 
  • The <ul> in the HTML is a bit out of place, but other than that it looks reasonable at a first glance.

    It would be possible to take a different approach and instead of manipulating CSS do replacement of actual DOM nodes. That might be better if you'd want to use <<set>> macros inside replacement texts, since you could then evaluate only the chosen option, while with CSS you evaluate everything but hide the irrelevant parts from view.
  • I think you're right, I think I just wanted to see if anyone else had written anything that could do that and they had.  I might try adapting it to do as you say though?  I'll have to do some more reading though as my understanding of javascript is very limited.  :)  Thank goodness for Google!

    Also, thanks for looking at it and giving me at least an idea of where to go.  :) 

    Made some more changes thanks to some helpful people at Stackoverflow:  codepen

    Do you think this is something that would be workable? 

    I guess it'd end up being something like:

    <<choiceblock>><<choice "1">><<choice "2">><choice "3">><<endchoiceblock>>

    <<answer "1">>You picked 1<</answer><<answer "2">>You picked 2<</answer>><<answer "3">>You picked 3<</answer>>

    Not quite as neat as what you originally proposed, but I couldn't quite figure out how to replace the choices with the right answer.
  • I ended up amending the original javascript as I couldn't nest new options in any answers.  I think I need one more change (to sort out the order in which answers occur if you try to re-use an answer), but I'll post it here in case it's of interest to anyone and will update it as any fixes are made.  I know it might seem odd to spend all this time trying to do this given that Twine can do this natively, but I'm trying to convert a choicescript project that has a lot of little asides in the story that don't really do anything major (such as passage transitions etc).  If I was to map all of these choices out to separate nodes, I think the node map would get stupidly big and I'd rather be able to look at it and determine 'real' branches in the story, as opposed to any silly little branches which I just threw in for flavour. 

    Codepen: here

    Hopefully the code will also play nicely with other Twine macros (I'm hoping that I can still set variables within the various options), although that's probably too much to hope, but that will require further testing.  For getting this to work in Twine, see this post here

    Edit:  A more Twine friendly method on how to achieve choices without multiple passages can be found here.
Sign In or Register to comment.