Howdy, Stranger!

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

If nesting headache! (Sugarcube 2.11.0)

edited November 2016 in Help! with 2.0
Can't work out what I'm doing wrong here. As the player clicks each item in the Storage Hut they're taken to a passage which says '(item) taken)' then a timer returns them to the Storage Hut passage and the the descriptions should be different (depending on which item they took).

This is the code, which works perfectly until they return to the hut having taken both items, at which point I want a 'Hut is empty' message, but I get the whole list of alternatives printed at once!
<<if not $hasCans and not $hasShells>>
Clearly it's been used for storage and half a dozen [[cans of assorted food]] remain. On a lower shelf a small [[box of shells]] for a handgun are lieing in the dust.

The main [[entrance|housedoor]] to the house is a short dash across open ground.<</if>>

<<if $hasCans>>On a lower shelf a small [[box of shells]] for a handgun are lieing in the dust.
The main [[entrance|housedoor]] to the house is a short dash across open ground.<</if>>

<<if $hasShells>>Half a dozen [[cans of assorted food]] food sit on the shelves.
The main [[entrance|housedoor]] to the house is a short dash across open ground.<</if>>

<<if $hasCans and $hasShells>>The storage hut is empty.

The main [[entrance|housedoor]] to the house is a short dash across open ground.<</if>>

Comments

  • That's because if $hasCans and $hasShells are both true, then conditions #2 and #3 are by definition true on their own, as well. You need to test the most specific condition first, and hide the others behind an <<else>>, so they don't get tested individually unless the hut is clearly not empty.
  • edited November 2016
    As noted by felixp7, you have less specific conditions before more specific conditions, which is backwards. You should probably have one primary <<if>> here and two subordinate ones. You're also repeating yourself again. And you misspelled "lieing"—it should be "lying".

    Try something like the following:
    <<if $hasCans and $hasShells>>
    \The storage hut is empty.
    \<<elseif not $hasCans and not $hasShells>>
    \Clearly it's been used for storage and half a dozen [[cans of assorted food]] remain. On a lower shelf a small [[box of shells]] for a handgun are lying in the dust.
    \<<else>>
    \<<if not $hasShells>>
    \On a lower shelf a small [[box of shells]] for a handgun are lying in the dust.
    \ <</if>>
    \<<if not $hasCans>>\
    \Half a dozen [[cans of assorted food]] food sit on the shelves.
    \<</if>>
    \<</if>>
    
    The main [[entrance|housedoor]] to the house is a short dash across open ground.
    


    Frankly, that still repeats a bit much as the contents of the neither item condition and some item condition are almost identical. Something like the following would probably be even better:
    <<if $hasCans and $hasShells>>
    \The storage hut is empty.
    \<<else>>
    \Clearly it's been used for storage.
    \ <<if not $hasCans>>
    \Half a dozen [[cans of assorted food]] food sit on the shelves.
    \<</if>>
    \ <<if not $hasShells>>
    \On a lower shelf a small [[box of shells]] for a handgun are lying in the dust.
    \<</if>>
    \<</if>>
    
    The main [[entrance|housedoor]] to the house is a short dash across open ground.
    
  • edited November 2016
    Thanks, each. I honestly don't know how you wrap your head around these logistics. It just won't gel with me... you've probably noticed.
Sign In or Register to comment.