Hello,
It's also bugged me that variables cannot be set/unset in {if} sections.
Workarounds can be found most of the time but I think they can pose problem in certain cases.
Here's an example:
@set troll_sleeps
@set wearing_boots
squiffy.story.go("outside");
[[outside]]:
[[enter room.]](room)
[[room]]:
{if troll_sleeps:
Troll: 'zzz' <br>
{if wearing_boots:The troll wakes up.}
}
{else:Troll: 'hello'}
[[exit room]](outside)
So, we have a troll who's sleeping in a room. Upon entering the room, the troll gets woken up if wearing_boots is true.
What's missing in the previous code is the unsetting of troll_sleeps. Where should we put it?
1) The intuitive choice would be inside {if wearing_boots}:
{if wearing_boots:
@unset troll_sleeps
The troll wakes up.}
but as Alex explained that's not possible.
2) A workaround would be to unset troll_sleeps upon exiting the room, i.e.
{if wearing_boots:[[exit room]](outside, not troll_sleeps)}
{else:[[exit room]](outside)}
but that's inelegant for various reasons:
[list=a]
[*]What we really WANT is the troll waking up upon entering the room, not exting.[/*:m]
[*]If there's several exit links we need to replicate the code.[/*:m]
[*]What if stuff happens in the room, that depends on whether the troll is sleeping?[/*:m][/list:o]
In that case we need to find another workaround. The only one I see is
3) Add an intermediate section:
@set troll_sleeps
@set wearing_boots
squiffy.story.go("outside");
[[outside]]:
[[enter room.]](room)
[[room]]:
{if troll_sleeps:
Troll: 'zzz' <br>
{if wearing_boots:The troll wakes up.}
}
{else:Troll: 'hello'}
{if wearing_boots:[[continue]](room2, not troll_sleeps)}
{else:[[continue]](room2)}
[[room2]]:
Stuff happens here that depends on troll_sleeps.
[[exit room]](outside)
but that multiplies the number of sections, i.e. the number of clicks required by the player.
From a player perspective, this is not great (why make me click Continue if that's the only option anyway)
If I'm not wrong, I think there's no other choice than workaround 3), and I think it all comes down to Squiffy
not being able to change the value of an attribute in the middle of a same section:
[[section]]:
@set x=1
{x} should be 1 but is 2
@set x=2
{x} is 2
I am guessing this is due to the "@" statements being parsed and executed before
the text being interpreted. Which is a shame, but I suppose it's voluntary.
I'd like to confirm I'm not missing an obvious/more elegant solution.
Any thoughts on this?