Howdy, Stranger!

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

Audio only mistake (sugarcube 2.11.0)

I've made a bit of a mistake at one of my passages, where I'm wrongly relying on the audio to tell the player what's going on.

All this works as it should, but I need to trigger two lines of text - one for when the car starts, another for when it fails, but I have real problems with (if) nesting and don't know how to insert them into all this.
\ <<if visited() is 1>>The car's been ransacked, no doubt several times and a thorough search reveals nothing of value.
\ <<if $hasGas and $hasPlug>><<link "Two wires">><<audio "out_side" volume 0.1>><<audio "car_start" volume 100 fadeoverto 11 0.0>><<timed 10s>><<goto "village">><</timed>><</link>> hang from the broken plastic under the steering wheel.
\ <<else>>
\ <<link "Two wires">><<audio "car_fail" play>><</link>> hang from the broken plastic under the steering wheel. 

The road continues [[north.]]<</if>>
<<else>>
\The car's still here.
\ <<if $hasGas and $hasPlug>><<link "Two wires">><<audio "out_side" volume 0.1>><<audio "car_start" volume 100 fadeoverto 11 0.0>><<timed 10s>><<goto "village">><</timed>><</link>> hang from the broken plastic under the steering wheel.
\ <<else>>
\ <<link "two wires">><<audio "car_fail" play>><</link>> hang from the broken plastic under the steering wheel. 

The road continues [[north.]]<</if>>
<</if>>
As is stands, the player won't know what's going on if he has his speakers off or has disabled the sound from my options.

Comments

  • Resolved. I did away with all the (ifs) and created a couple of extra passage to handle the car start/fail stuff.
  • It's no wonder you have problems with nesting your <<if>> logic. You seem to habitually make everything more complicated than it needs to be. In particular, you are repeating yourself yet again—both visited cases vary by only a single line of text and both car start cases use the same text. You should really stop duplicating identical text all over the place, you're only making things more complicated, and thus confusing, for yourself. Try something like the following:
    \ <<if visited() is 1>>The car's been ransacked, no doubt several times and a thorough search reveals nothing of value.
    \<<else>>The car's still here.
    \<</if>>
    \ <<if $hasGas and $hasPlug>><<link "Two wires">><<audio "out_side" volume 0.1>><<audio "car_start" volume 100 fadeoverto 11 0.0>><<timed 10s>><<goto "village">><</timed>><</link>>
    \<<else>><<link "Two wires">><<audio "car_fail" play>><</link>>
    \<</if>> hang from the broken plastic under the steering wheel.
    
    The road continues [[north.]]
    


    Now, to address the the no/muted audio issue. As one possible, and easy, solution—there are many—you could simply replace <<link>> with <<linkappend>> and provide a suitable set of text for each case. For example—and based on the above example:
    \ <<if visited() is 1>>The car's been ransacked, no doubt several times and a thorough search reveals nothing of value.
    \<<else>>The car's still here.
    \<</if>>
    \ <<if $hasGas and $hasPlug>><<linkappend "Two wires" t8n>>, which you use to hotwire and start the car,<<audio "out_side" volume 0.1>><<audio "car_start" volume 100 fadeoverto 11 0.0>><<timed 10s>><<goto "village">><</timed>><</linkappend>>
    \<<else>><<linkappend "Two wires" t8n>>, which do nothing when you attempt to hotwire the car,<<audio "car_fail" play>><</linkappend>>
    \<</if>> hang from the broken plastic under the steering wheel.
    
    The road continues [[north.]]
    
    NOTE: Unlike <<link>>, <<linkappend>> generates output, so you should ensure that no extraneous whitespace or other output will be generated.

    PS: If you like the solution, but not the transition of the text, simply remove both t8n keywords.
  • Thank you.

    I can only stress that <<if>> nesting simply won't gel with me. I can't help it. I do try.

    Even with your good script in front of me, I still don't understand what it is you've done. I can see you've broken up the sentences and placed part of it after <<else>> macros, but I just don't know or understand what goes where.
Sign In or Register to comment.