Howdy, Stranger!

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

'if' / 'else' minefield!

edited November 2016 in Help! with 2.0
Can someone please decipher this and tell me where I'm going wrong? I want the same passage's description to change if the camp fire is lit, but I also have to try and juggle a plethora of other conditions.

When I run this I don't get any error messages, but the descriptions are all to cock. Sometimes I get two 'firepit' (a dead one and a live one), and sometimes the description just stops mid-sentence as I to and fro between the passages.
<<if $fireLit>>It's not much comfort, but some heat does begin to radiate from the flames. <<if $hasRawMeat>>The embers are hot enough to cook on.<</if>> The<<if $hasRawMeat>> traps<<else>>traps are set in the forest.<</if>><<else>>A forest clearing. Freezing tempertures setting in. All the trees are either dead or dying and <<if $hasWood>>dead wood<<else>>dead wood<</if>> litters the floor. A dead <<if $hasWood and not $isfireLit>><<click "firepit">><<goto "Outside">><<set $fireLit to true>><</click><<else>>firepit is nearby and the <<if $hasRawMeat>> traps have been checked.<</if>><<else>>traps<</if>> are set in the forest.
<<if $isFireLit>><<audio "fire_crackling" loop play>><</if>>
<<audio "out_side" loop play>><</if>>

Thanks in advance.

Comments

  • Please use the code tag when you're posting code—it's C on the editor bar.


    I'd strongly suggest using line continuations or the <<nobr>> macro, either of which will allow you to break <<if>> mazes like that up a bit, thus making it easier to figure out what's happening.

    Your primary issues seem to be:
    1. Your <<if>> logic is a bit wonky in a few places and simply broken in others.
    2. You're missing one of the right angle brackets on the closing <</click>> tag. Also, <</click>> is deprecated, I'd suggest using its replacement, the <<link>> macro, instead.
    3. You're using <<goto>> when you don't need to and using it improperly to boot. If you're going to use it within a <<link>>/<<button>> (or <<click>>) it should be the very last thing.
    4. You're repeating virtually identical trap logic whether $fireLit is true or not. I'd suggest moving it outside so that you aren't repeating it.
    NOTE: If $fireLit is initially false, you'll end up with both audio tracks, "out_side" and "fire_crackling", playing once the player lights the fire pit. I'm unsure if that's intentional or not, but I figured that I'd mention it just in case.

    Try something like the following: (using line continuations for readablity)
    <<if $fireLit>>
    \  <<audio "fire_crackling" loop play>>
    \  It's not much comfort, but some heat does begin to radiate from the flames.
    \  <<if $hasRawMeat>>The embers are hot enough to [[cook]] on.<</if>>
    \<<else>>
    \  <<audio "out_side" loop play>>
    \  A forest clearing. Freezing tempertures are setting in. All the trees are either dead or dying and <<if $hasWood>>dead wood<<else>>[[dead wood]]<</if>> litters the floor.
    \  A dead <<if $hasWood>><<link "firepit" "Outside">><<set $fireLit to true>><</link>><<else>>firepit<</if>> is nearby.
    \<</if>>
    \  The <<if $hasRawMeat>>traps have been checked<<else>>[[traps]] are set in the forest<</if>>.
    
  • edited November 2016
    Thank you for taking the time to do this. It works perfectly and is a lot easier on the eye than my jumbled mess.

    The two audio track playing at the same time is intentional and you've also answered my next question. When I play tested the other day the fire audio didn't kick in and I was wondering if it wasn't possible to play two track at the same time.

    Now that I know my code was all broken that probably explains it, and both do play with your revised version.
Sign In or Register to comment.