Howdy, Stranger!

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

Refreshing/updating a passage without linking to itself

You can do that, right? Can't find it in the wiki, but I'm sure I read about it somewhere. To be clear, I want to refresh a passage after changing some variables when a <<replace>> link is clicked. Because it's in a <<replace>> I don't think I can link back to the passage normally... I guess <<timedgoto>> might work... but is there an existing tidy solution, something like <<passageupdate>>?

Thanks for reading!

Comments

  • Is this Sugarcube you're talking about? Because I have that same issue. As far as I remember Sugarcane updates variables so you don't need to do this. I could be remembering wrong, Ive been developing my game on Sugarcube since like 3 weeks ago.

    If there's a better way to do it than reloading the entire page or using jQuery to rewrite the innerHTML of specific IDs, I'd be interested to know, because I've had to code my way around a lot of issues that come from having to use state.display().
  • Real quick, in my Dumb Terminal stylesheet, there is code to update a passage.
  • Oh, a history prototype mod. Well that's crazy. It completely breaks Sugarcube though. In vanilla headers it doesn't break, but it still doesn't seem to do what I'm thinking it should.
    <<set $apple += 1>>

    You have <<print $apple>> apples.

    <<set $apple += 1>>

    <<display 'Update Regions'>>
    If this updates the passage, you would expect it to read "You have 2 apples."

    But it doesn't. It says you have 1 every time. Am I misunderstanding what this does?
  • For an in-progress game I'm working on I made a really bespoke alteration to L's revision macro code that let me selectively reload chunks of cycle text (you can kind of see it in action here though it's only used like, once); I could probably break it out into its own macro if it was needed, but I vaguely remember TheMadExile writing up a really simple reloading macro in SugarCube... somewhere?
  • Nifty little menu there. It seems to do what Mostly wants.

    As for Sugarcube, Thomas and I briefly spoke about this issue here and he seemed to be indicating to me that either targeting divs with jQuery or reloading the passage entirely with state.diplay("Passage", null, "back") was the way to go. If he made a macro he didn't bring it up.
  • In SugarCube, refreshing the current passage upon click without modifying the state history is fairly straightforward.  You can actually do what the OP wants in one of two ways (there are more, but these are probably the easiest).

    1. By redisplaying the entire passage using a little JavaScript, via state.display().

    An example passage: ($carrots was previously initialized elsewhere)

    You have <<print $carrots>> carrots.

    <<click "Refresh, with more carrot-y goodness">>

    /% modify your variables %/
    <<set $carrots++>>

    /% redisplay the currently active passage %/
    <<script>>state.display(state.active.title, null, "back")<</script>>

    <</click>>
    What the third parameter to state.display(), "back", actually means is: display the given passage without altering the state history (i.e. just display the given passage).

    2. By using two passages with <<display>> and <<replace>>. (I'm referring to SugarCube's <<replace>> macro here, not Leon's)

    For example:

    Passage "Carrot": (you link to this one)

    <span id="carrot-display"><<display "Display Carrots">></span>

    <<click "Refresh, with more carrot-y goodness">>

    /% modify your variables %/
    <<set $carrots++>>

    /% replace the sub-passage display %/
    <<replace "#carrot-display">><<display "Display Carrots">><</replace>>

    <</click>>
    Passage "Display Carrots": (you don't link to this one)

    You have <<print $carrots>> carrots.
  • TheMadExile wrote:


    1. By redisplaying the entire passage using a little JavaScript, via state.display().



    Thank you for this tip. I'm using this to turn a debugging variable on and off, and then refresh the passage so the debugging data is displayed or removed.
  • Is there a way to use option 1 without the page looking like it is refreshing, as far as the fade in effect, without giving up the fade in effect happening on a normal transition to a new passage?
  • dootdoot wrote:

    Is there a way to use option 1 without the page looking like it is refreshing, as far as the fade in effect, without giving up the fade in effect happening on a normal transition to a new passage?


    Possibly, depending on exactly what you're doing, but it's probably more trouble than it's worth.

    The basics would be that you'd need to add a class to #passages (or something like that), which would disable the passage transition animation for the call to state.display(), and then remove the class afterwards.  Timing issues could make that hairy though.
Sign In or Register to comment.