Howdy, Stranger!

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

How can I check existence of particular passage in Sugarcube?

Hello!
How can I check existence of particular passage in Sugarcube?
I saw that Harlowe has system variable "$Passages" which can solve this task, but is there any way to do it in Sugarcube?

Thank you.

Comments

  • To check if a passage exists within the story history, you may use the visited() utility function (I suggest reading the linked docs). For example:
    <<if visited() is 3>>…this is the third visit to the current passage…<</if>>
    <<if visited("Bar")>>…has been to the Bar at least once…<</if>>
    <<if visited("Café") is 1>>…has been to the Café exactly once…<</if>>
    <<if visited("Bar", "Café") is 4>>…has been to both the Bar and Café at least four times…<</if>>
    
  • <<if visited() is 3>>…this is the third visit to the current passage…<</if>>
    <<if visited("Bar")>>…has been to the Bar at least once…<</if>>
    <<if visited("Café") is 1>>…has been to the Café exactly once…<</if>>
    <<if visited("Bar", "Café") is 4>>…has been to both the Bar and Café at least four times…<</if>>
    

    Hm, but what difference will it give if one passage exists, but never visited, and other never existed?
  • Why would you ever check for the existence of a passage which you, the author, know doesn't exist within the story?

    Regardless. The answer is none (i.e. there is no difference). The visited() utility function doesn't check if passages exist within the story, it checks if they exist within the story history (exactly the same as checking Harlowe's $Passages variable, AFAIK). If a passage doesn't exist within the story history, regardless of whether or not it exists within the story, then its count is 0 (zero).
  • Why would you ever check for the existence of a passage which you, the author, know doesn't exist within the story?
    Well, it looks like I need that check.

    I think I'll try my luck with custom macro. Thanks for your time.
  • Why do you need to check for a passage which you haven't created? I'm seriously failing to understand why you think that you need to do this.

    Regardless. You may use the Tale API's has() method to do so, like so:
    → Returns whether a Passage object matching "The Ducky" exists within the story
    tale.has("The Ducky")
    

  • edited May 2015
    I'm trying to emulate parser-games-like behaviour, when several objects share similar action between them. So I have default response for that action. But I also have individual responses for couple of objects.

    And when I decide what to show, I check - does object have own response or I should use default.

    It would be trivial if responses were strings. But I have links in them and should use <<display "passage">> instead. And here I have my is-passage-exist check.

    I hope I made it clear?
  • cheshire wrote: »
    And when I decide what to show, I check - does object have own response or I should use default.
    You've probably thought of this, but sometimes, it's amazing how we can all overlook simplest solutions.

    Can you just make it check a variable/object property for whether or not it has its own response?
  • Sharpe wrote: »
    You've probably thought of this, but sometimes, it's amazing how we can all overlook simplest solutions.
    My worst fear it is )
    Sharpe wrote: »
    Can you just make it check a variable/object property for whether or not it has its own response?
    Yeah, it was my Plan B - make switches for every case and check them. But number of switches = number of objects * number of common actions and it doesn't really motivates.

    Anyway, I think I found some dirty solution - check for those passages in "store-area" of compiled webpage with JS.
  • cheshire wrote: »
    I'm trying to emulate parser-games-like behaviour, when several objects share similar action between them. So I have default response for that action. But I also have individual responses for couple of objects.

    And when I decide what to show, I check - does object have own response or I should use default.
    Alright. That makes sense.

    cheshire wrote: »
    Anyway, I think I found some dirty solution - check for those passages in "store-area" of compiled webpage with JS.
    I just told you how you can do what you want to do, by using tale.has(). It does exactly what you want (checking to see if the passage exists at all), there's absolutely no need to brute force check the passage store area. For example:
    <<if tale.has($playerInput)>>\
    <<display $playerInput>>\
    <<else>>\
    <<display "default response">>\
    </if>>
    

    Additionally, a suggestion. Since passage titles are case-sensitive, you may want to title all of your
    passages in lowercase and force the player's input to lowercase, otherwise player's may become frustrated by things like "Go west" not matching "go west".
  • edited May 2015
    I just told you how you can do what you want to do, by using tale.has(). It does exactly what you want (checking to see if the passage exists at all), there's absolutely no need to brute force check the passage store area. For example:
    <<if tale.has($playerInput)>>\
    <<display $playerInput>>\
    <<else>>\
    <<display "default response">>\
    </if>>
    

    Oh... All this time I thought that whole API section in manual relates to JS only... Now I see, thank you.
    Additionally, a suggestion. Since passage titles are case-sensitive, you may want to title all of your
    passages in lowercase and force the player's input to lowercase, otherwise player's may become frustrated by things like "Go west" not matching "go west".

    Actually, I don't use input - I don't really believe in parser-based IF in its current form - my game uses links. But I try to emulate object model of parser games. Still, thanks for the tip.
Sign In or Register to comment.