Howdy, Stranger!

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

Problamatic 'visited' issue is SugarCube.

I'm using an 'if / else' variable to change the description of a location on second visit, but I'm wondering if it's at all possible to prevent the 'else' taking effect if the player is returning from the game's inventory.

If a player is at this location, and decides to click on their inventory in the sidebar, their return means the 'else' description will trigger. It's important that it only does this if the player is returning from a specific passage.

Here's the whole passage:
<<if not $visitedBody>>\
<<set $visitedBody to true>>\
The crow takes off.

Clearly a body, and very dead. The poor man's face is bloated, blotched with green.

A backpack lies trapped benath him.

A quick search of the dead man's pockets reveal a pocket knife and a box of bullets.

[[Push on]]
<<click [[Take everything|Approach object]]>><<set $hasBullets to true>><<set $hasKnife to true>><<set $hasPack to true>><<set $hasClearLiquid to true>><<set $hasSleepingBag to true>><<set $hasHoodedFleece to true>><<set $hasBakedBeans to true>><</click>>
<<else>>\
The body lies plundered.

[[Push on]]
[[Examine takings->packcon]] <</if>>

I only want the 'else' description to trigger if the player clicks on 'Take everything', otherwise they'll lose their chance to do so.

Comments

  • Also, is there a way to change the description twice?

    i.e

    First visit - first description
    Second visit - second description
    Third visit - third description
  • Jud_Casper wrote: »
    I only want the 'else' description to trigger if the player clicks on 'Take everything', otherwise they'll lose their chance to do so.
    You could move the $visitedBody state modification into the <<click>> macro. For example:
    <<if not $visitedBody>>\
    The crow takes off.
    
    Clearly a body, and very dead. The poor man's face is bloated, blotched with green.
    
    A backpack lies trapped benath him.
    
    A quick search of the dead man's pockets reveal a pocket knife and a box of bullets.
    
    [[Push on]]
    <<click [[Take everything|Approach object]]>>
    	<<set $visitedBody to true>>
    	<<set $hasBullets to true>>
    	<<set $hasKnife to true>>
    	<<set $hasPack to true>>
    	<<set $hasClearLiquid to true>>
    	<<set $hasSleepingBag to true>>
    	<<set $hasHoodedFleece to true>>
    	<<set $hasBakedBeans to true>>
    <</click>>
    <<else>>\
    The body lies plundered.
    
    [[Push on]]
    [[Examine takings->packcon]] <</if>>
    
    Though it might be more descriptive in that case to name the variable something like $plunderBody.

    Tip: The contents of a <<click>> macro are silent, so you don't usually have to worry about whitespace there. Meaning that you may, as in my above example, use indention/line breaks to make things more readable for yourself.

    Jud_Casper wrote: »
    Also, is there a way to change the description twice?

    i.e

    First visit - first description
    Second visit - second description
    Third visit - third description
    Sure.

    If using variables. Instead of using a boolean flag, use an integer counter. For example, in the StoryInit special passage:
    <<set $visitedSomePlace to 0>>
    
    And then in the specific passage:
    <<set $visitedSomePlace++>>\
    <<if $visitedSomePlace is 1>>\
    First visit - first description
    <<elseif $visitedSomePlace is 2>>\
    Second visit - second description
    <<else>>\
    Subsequent visits - third description
    <</if>>
    

    If using the visited() function.
    <<if visited() is 1>>\
    First visit - first description
    <<elseif visited() is 2>>\
    Second visit - second description
    <<else>>\
    Subsequent visits - third description
    <</if>>
    
  • Brilliant! The 'visitedBody' solution worked like a dream!

    Also thanks for the multiple visits formula. It can get so damn confusing for a beginner, knowing how to nest correctly is something that gets me in a right muddle.
Sign In or Register to comment.