Turnscript not enabling
Pigbeetle
23 Nov 2022, 10:16I can get a match to light succesfully, and illuminate the room, but it's only supposed to work for a certain number of turns, before snuffing itself out. I could just set a timer script, but I'm trying to use a turnscript, as per this tutorial:
https://docs.textadventures.co.uk/quest/handling_light_and_dark.html
But no matter what happens, the turnscript just isn't doing anything at all. The match stays lit no matter how many turns are taken.
When you "light match" I have this run: and it works for lighting up the room as it should
SetLight (Campsite)
msg ("You strike the match across the book and it lights, illuminating your environment just enough to look around.")
EnableTurnScript (match)
And this under the match turnscript:
Matches.stick = Matches.stick - 1
if (Matches.stick < 1) {
Matches.lit = false
Matches.lightsource = false
DisableTurnScript (match)
msg ("The flame reaches the end of the matchstick and fizzles out and your lightsource disappears, but not before burning your thumb and index finger, causing you to reflexively twitch and launch it off somewhere into the darkness..")
RemoveObject (Matches)
}
I literally just copied the code from that tutorial and swapped my attribute names, "stick" being how much stick is left of the match, and lit obviously being if it's lit or not.
So even though I clearly enable the match turnscript once its lit, the countdown does not start. I've tried even setting the stick integer just to 1 and making many moves in an attempt to get it to do something, but it just doesn't.
Am I misunderstanding that the "Matches.stick - 1" bit is supposed to decrease the stick integer by 1 each turn made?
Pigbeetle
23 Nov 2022, 11:02Nevermind I had the turnscript under the actual matches, not on its standalone thing in the general list of things in the game. Hence what I get for trying to keep things more compact :P
mrangel
23 Nov 2022, 13:38Yeah; turnscripts and commands need to be either in the player's current room, or outside any location.
Oddly enough, if you want to put them somewhere else to make it more organised in the editor, you could use RemoveObject (match)
to shift them to the global list when you enable them.
For stuff like this, where a turnscript relates to a specific object, I sometimes find it easier to make a turnscript that just looks at all the objects. Something like:
foreach (obj, AllObjects()) {
if (HasScript (obj, "turnscript")) {
do (obj, "turnscript")
}
}
and then you can give the match a script attribute named turnscript
doing something like:
if (GetBoolean (this, "lit")) {
this.stick = this.stick - 1
if (this.stick < 1) {
this.lit = false
msg ("The flame reaches the end of the matchstick and fizzles out and your lightsource disappears, but not before burning your thumb and index finger, causing you to reflexively twitch and launch it off somewhere into the darkness..")
RemoveObject (this)
}
}
To me, that seems to make things easier to organise, because the match's script is on the match rather than in a separate turnscript.