Howdy, Stranger!

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

Changing location description on return visit?

I've checked the threads under the Sugarcube 1 tag, to no avail.

I want to set some form of flag when a player visits a location, so that on return he gets a slightly different description.

For instance, on first visit:

A long road, nothing ahead.

Early signs of thirst.


And on the player's return:

A long road, nothing ahead.

How would I do this, please?

Comments

  • You could either use a $variable flag or the visited() function.

    If you plan to have many such passages, using the visited() function is probably the better overall choice. Flags are more flexible, however—for example, you could have a flag for an entire region, rather than simply one passage. Also, flags work within included passages (via the <<display>> macro), while the visited() function may not (depending on what you're trying to do, anyway).

    With a $variable flag:
    <<if not $visitedLongRoad>>\
    <<set $visitedLongRoad to true>>\
    A long road, nothing ahead.
    
    Early signs of thirst.
    <<else>>\
    A long road, nothing ahead.
    <</if>>
    
    And initialize $visitedLongRoad in the StoryInit special passage:
    <<set $visitedLongRoad to false>>
    

    With the visited() function:
    <<if not visited()>>\
    A long road, nothing ahead.
    
    Early signs of thirst.
    <<else>>\
    A long road, nothing ahead.
    <</if>>
    
  • Thanks, TME. I'd nearly staggered my way there. I was just lacking the 'else' statement.

    Thank you again.
  • edited November 2015
    Mmm, it's not working for me. I keep getting the 'else' option, even on my first visit.

    Could it have anything to do with my cache?

    I'll try the variable option.

    [edit] The variable option works :)
  • edited November 2015
    Jud_Casper wrote: »
    Mmm, it's not working for me. I keep getting the 'else' option, even on my first visit.
    Whoops. Slight error there. Mea culpa.

    The above visited() function example should have been:
    <<if visited() is 1>>\
    A long road, nothing ahead.
    
    Early signs of thirst.
    <<else>>\
    A long road, nothing ahead.
    <</if>>
    

    Alternatively, since you really only want to know if the player has ever been to that passage before, either the lastVisited() function or the state.has() method would be ever so slightly more efficient (though it's unlikely to be noticeable in practice). The reason being is that they return as soon as they find an instance of the passage with the history, while visited() iterates over the entire history counting every instance of the passage within the history.

    With the lastVisited() function:
    <<if lastVisited(passage()) is -1>>\
    A long road, nothing ahead.
    
    Early signs of thirst.
    <<else>>\
    A long road, nothing ahead.
    <</if>>
    

    With the state.has() method:
    <<if not state.has(passage())>>\
    A long road, nothing ahead.
    
    Early signs of thirst.
    <<else>>\
    A long road, nothing ahead.
    <</if>>
    
Sign In or Register to comment.