Howdy, Stranger!

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

Possible to store current passage name into a variable?

Another newbie question.

Is it possible to store the name of the current passage the player is in, into a string variable?

And if so is there an expression to be able to compare players current passage with the one stored in the string regarding the above question?

I hope that makes sense.

Comments

  • I think the code you're looking for is:
    <<set $location to state.history[0].passage.title>>
    This won't work inside <<display>>s -- or rather, it won't give you the passage title of the displayed passage, it'll give you the passage title of whatever "real" passage you're in; that might not matter for what you're using it for.

    (and so then the comparison of that stored variable to the current passage would just be
    <<if $location eq state.history[0].passage.title>>
    )

    ...it's also possible you could do whatever you're trying to do with the previous() or visited() functions in Twine 1.4, which might be a little simpler, depending.
  • xax wrote:

    I think the code you're looking for is:
    <<set $location to state.history[0].passage.title>>
    This won't work inside <<display>>s -- or rather, it won't give you the passage title of the displayed passage, it'll give you the passage title of whatever "real" passage you're in; that might not matter for what you're using it for.

    (and so then the comparison of that stored variable to the current passage would just be
    <<if $location eq state.history[0].passage.title>>
    )

    ...it's also possible you could do whatever you're trying to do with the previous() or visited() functions in Twine 1.4, which might be a little simpler, depending.


    Im getting an error with this "<<if>> bad condition: missing ; before statement" when I used the
    <<set $location to state.history[0].passage.title>>
    Any chance of a demo being whipped up?

    I presume the checking bit would be like <<if $location eq state.history[0].passage.Room A>>[/code] ?

    Here is what I am hoping to do, so correct me if this is a bad method or a better method can be used. I want to keep it simple as possible.

    I want to create many rooms/passages that will have some enemies and other things or new options inside.  I thought if I have one single passage that checks specific rooms/passages with a lot of IF Statements, it would be easier to keep track of which locations/passages have what if its all in one place. It saves time searching through individual passages to find what I am looking for if I want to make changes. I will still use tags and comments for reference, but still can be time intensive to look. So player enters room A, it matches in the check and he is given a link with a new option to choose or there is an event that happens.

    I hope this makes sense.  I plan to use the update macro /with footer script so for every passage the player goes to, the game will run that check passage and try to match players current location/passage and output something if there is a match. 


    Thanks.
  • I'm not sure what would cause that error; I wrote up a little demo twee file that worked properly. Here it is:
    ::Start
    (Start)
    [[foo]]
    [[bar]]
    [[baz]]

    ::foo
    foo passage
    * ''foo''
    * [[bar]]
    * [[baz]]
    <<display "footer">>

    ::bar
    bar passage
    * [[foo]]
    * ''bar''
    * [[baz]]
    <<display "footer">>

    ::baz
    baz passage
    * [[foo]]
    * [[bar]]
    * ''baz''
    <<display "footer">>

    ::footer
    <<set $location to state.history[0].passage.title>>
    <<if $location eq "foo">>You're in passage "foo"
    <<else if $location eq "bar">>You're in passage "bar"
    <<else>>You're somewhere else!!
    <<endif>>
    ...which is raw twee code that generates a file that doesn't error -- you might be able to import that into Twine somehow, otherwise just manually copy/paste the contents of each passage (::Start, ::footer, etc) into correctly-named passages in Twine. Hopefully it's fairly clear how the whole state.history thing works.

    The $location value itself will be set to a simple string -- if you know exactly the passage you want to match against, you can just say so (like in the above, where it's compared to "foo" and "bar" passages). It's only if you want to check the stored location against the current passage you'd need to say &lt;&lt;if $location eq state.history[0].passage.title&gt;&gt;, so it sounds like that's unnecessary for what you're doing.
Sign In or Register to comment.