0 votes
by (200 points)

Having trouble with getting this code to work 

(if: $package is true)[
[[Head to Zenet's house]] 
[[Go back inside]] 
<audio src="gobackinsidepackagefalse.mp3" autoplay>
]
(else-if: $offence is true but $package is false)[
(set: $offence to false)
[[Try Again | Begin]]
[[Start Over | Set Up]]
<audio src="gobackinsideoffencetrue.mp3" autoplay>
]
(else:)[
[[Try Again | Begin]]
[[Start Over | Set Up]]
<audio src="gobackinsideoffencefalse.mp3" autoplay>
]

I've tried it a few different ways and can't seem to get it running without an error message. Mostly it's telling me that my expressions are badly written which is a common problem for me tbh hahahaha. Any advice? 

2 Answers

+1 vote
by (63.1k points)
There is no TwineScript operator called "but". You probably mean "and". There may be other problems too, I didn't read your code super carefully, but that seems like the big one.
0 votes
by (159k points)

Please use the correct Question Tag to state the name and full version number of the Story Format you are using, and please don't include that information in the Question Title.

As explained by @Chapel but is not one of the Boolean Data operators, you would generally use the and or the or operator to join two sub-expressions together.
eg.

(if: $hasHammer and $hasNail)[You put up the painting!]

(if: $strength is 6 or $agility is 8)[You climb the high wall]


The following is a corrected version of your example...

(if: $package)[
[[Head to Zenet's house]] 
[[Go back inside]] 
<audio src="gobackinsidepackagefalse.mp3" autoplay>
]
(else-if: $offence)[
(set: $offence to false)
[[Try Again|Begin]]
[[Start Over|Set Up]]
<audio src="gobackinsideoffencetrue.mp3" autoplay>
]
(else:)[
[[Try Again|Begin]]
[[Start Over|Set Up]]
<audio src="gobackinsideoffencefalse.mp3" autoplay>
]

... the following changes have been made:

1. I removed the unnecessary is true and is false comparisons, for reasons I have previously explained to you.

2. I remove the unnecessary $package is false check of your (else-if:) macro.

I did this because a set of (if:) and (else-if:) macros are processed in the order that they are encountered, and as soon as one macro of the set evaluates to true then the processing of the set stops.

If $package equalled true then the (if:) macro would evaluate to true and the code within it's associated hook will be executed, and the (else-if:) and (else:) macros will NOT be checked. So this means that the only way for the (else-if:) macro to be checked is if $package equalled false, which means there is no need to include that check in the (else-if:) macro's conditional expression.

3. I remove the invalid space characters at the start of the Target Passage Name part of your Markup based links.

Adding space characters to either end of a Target Passage Name can result it the automatically created missing Passage to also have those spaces in it's Name, which makes the Passage Name invalid.

/% BADLY Formatted Markup based link. %/
[[Try Again | Begin]]

/% CORRECTLY Formatted Markup based link. %/
[[Try Again|Begin]]

note: I didn't test your audio HTML elements.

by (200 points)
Changing but to and worked a treat thanks very much Chapel!:)

Apologies I should have read the post rules better I was in a bit of a flap at the time hahaha will bear that in mind if I post again.

I originally had changed all of my macros to not include true or false indicators but that seemed to be cause further issues, perhaps there was something else I was doing wrong? But for the moment I've kept it as is as it is working that way.

Overall it's probably a wee bit of a bodge but at this point I'm just happy it runs as it should hahahaha:)

Thanks again for your help!
...