Howdy, Stranger!

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

Help with if statements (newbie)

<<if tags().previous != "inv">>
<<set $room.last = previous()>>
<<endif>>
The above code is supposed to set room.last to previous unless previous has a tag inv. It instead sets any room. Even if it does have that tag. What am I doing wrong?

Comments

  • You need to state which Story Format (name and version) you are using when you ask a question, as answers can be different for each one. I am going to assume you are using SugarCube 1.x

    I am also assuming your $room variable is defined something like:
    <<set $room to {last: ""}>>
    
    Try using the following:
    <<if ! tags(previous()).contains("inv")>>
    	<<set $room.last to previous()>>
    <<endif>>
    
  • edited April 2016
    Virtually everything, within the conditional anyway. It should be something like the following:
    <<if not tags(previous()).contains("inv")>>
    <<set $room.last to previous()>>
    <</if>>
    

    Alternatively, and assuming that this is to allow you to return to the last passage not tagged with inv—for a nested/multi-passage inventory or something to that effect—an equivalent method would be to set $room.last to passage() unless the current passage's tags contains inv. For example:
    <<if not tags().contains("inv")>>
    <<set $room.last to passage()>>
    <</if>>
    
  • thankyou.. Everyone for your help. this is a great piece of software.
Sign In or Register to comment.