Flags and variables in TADS3

Great!
I’ll throw out a few more words, hopefully only to simplify your life as you go forward.
Particularly with yikes-long names like the battery holder :slight_smile: you’ll want to make use of self and the ability to refer to an object’s own properties without qualifiers. Thus:
if(nuclear_Battery.isIn(self))
and
makeOpen(nil)

Within the check method (of Open, in this case) you might want to get used to using
if(battery.isIn(self)) failCheck('Don\'t mess with it. ');

I would write notifyInsert like this:

notifyInsert(obj,newCont) {
    if(obj==battery) { ... }
    else inherited(obj,newCont);
}

if nothing else, just as a habit to get into so you don’t burn yourself later on.
It is also a good habit to get into to write like this:

check {
       if(battery.isIn(self)) failCheck('msg. ');
       else inherited; 
}

just in case you are dealing with a verb that carries “normal” handling in the check method. Again, it’s better to establish the habits so you don’t burn yourself.

(Possible information overload:) Implementing the holder as a SingleContainer isn't really necessary if only one game object is allowed to go in the container. All SingleContainer does is enforce the objEmpty precondition.
You’ll also want to make sure you have a custom cannotPutInMsg(obj) to clue the player that only the battery is going in the compartment.

I can’t resist the extra touches! If you define

unBattery: PresentLater, Unthing 'battery' 'battery'
      'The battery is locked inside the compartment. '
      location = Power_plant
;

and add a code line at the end of notifyInsert

unBattery.makePresent;

Then the game will look a little more graceful when the player tries to refer to the battery after it’s in the holder.

2 Likes