Placing objects in my starting room - TADS3.1

With some difficulty, I’m trying to place objects into my first room. I’ve included the source that’s giving me problems. In this source, I hope to place a backpack into the slatted box. When I test the compiled game, the pack is shown even though the box is closed and locked. Also, when I try to wear the pack, I get a runtime error in 'en_us.t? Here’s the troublesome code. Could use some help./[code]

/*******************************************************************************
* (Room0001) The player begins the game at this location.                      *
*******************************************************************************/ 

Room0001:OutdoorRoom 'At The Beach' 'At the Beach'
roomFirstDesc()
{
"You have just arrived at the beach.";
beachAchievement.awardPointsOnce();
}
shortDesc="You are at the sandy beach."
 
beachAchievement:Achievement{+5 "reaching the beach"}
;
 /* Add HELP sign to beach area. **********************************************/
 
class Sign : Readable
;
+sign: Sign, Fixture 'large metal sign' 'metal sign'
"A sizeable metal sign is firmly attached to a large tree near the start of the
eastern path. It is quite rusty and worn but the printing on it can still be
read. It just might provide some information about The Magic Forest."
initSpecialDesc = "Attached to a tree at the beginning of the eastern is a large
metal sign." 
cannotTakeMSG = 'It is held permanently in place. Besides, there is no reason to
try to take it.'
readDesc = "The sign is written in both English and Spanish and reads: 
'DANGER! Restricted property beyond this point. Enter at your own risk.'\b
Property Manager,\b
Melenkurian\b" 
dobjFor(Read)
{
 action()
 {
  readsignAchievement.awardPointsOnce(); 
  inherited;
 }
}readsignAchievement : Achievement { +5 "reading the sign at the beach" }
;

/* Add slatted-wood box. ******************************************************/ 

+box: ComplexContainer, Fixture'large slatted wooden (wood) box*boxes' 'large
slatted-wood box' 
"The large wooden box, left here from a previous helicopter, lies on some small
rocks. At it top, there is a hasp that can be turned to unlock ir lock it. " 
cannotTakeMsg = (backpack.seen ? 'The backpack is a much more convenient
container. You would be better off using it instead.' : 'The box is way to
heavy to try to lift or carry around.')
initSpecialDesc = "A large slatted-wood box is lying nearby on some small
rocks." 
subContainer: ComplexComponent, LockableContainer
{
currentlyLockedMsg = 'The hasp is at the currently locked position. '
CurrentlyUnlockedMsg = 'The hasp is currently at the unlocked position. '
dobjFor(Lock)
{
 action()
 {
  "You twist the hasp and lock the box shut.";
  inherited;
 }
}
dobjFor(Unlock)
{
 action()
 {
  "You turn the hasp, allowing the box to be opened.";
  inherited;
 }
}
}
;
++ Component 'hasp' 'hasp'
"A simple hasp that does the job of unlocking and locking the box."
 dobjFor(Turn) {remap = [box.subContainer.isLocked ? UnlockAction :
 LockAction, box.subContainer]}
;

 ++backpack : BagOfHolding, Attachable, Wearable, OpenableContainer
'back pack/backpack' 'backpack'
"It is a standard military backpack which allows a sleeping bag to be attached
 to it at the bottom. It has a large main compartment which can be opened or
 closed from the top. If you wear this pack, you can store many objects in it,
 allowing you to possess a larger number of them than if you tried to carry them
 in your hands. "
 /*location = box.subcontainer*/
bulkCapacity = 3000
minBulk = 1

affinityFor(obj)
{
 return obj.ofKind(Matchbook) ? 50 : inherited(obj);
}
dobjFor(Wear)
{
action()
{
"You sling the backpack over your shoulders. ";
wearpackAchievement.awardPointsOnce();
inherited;
}
}
wearpackAchievement : Achievement { +5 "wearing the backpack"}
; 

You can’t put things into ComplexContainers using the ++ notation. Try this:

backpack : BagOfHolding, Attachable, Wearable, OpenableContainer @box.subContainer

When you do it this way, also, you’ll need to be careful to move it out of the containment tree. What I usually do is park items that are not (for one reason or another) part of the containment tree at the top of the code for the room, above the Room definition itself. That’s safe.

You haven’t made the subContainer initiallyOpen = nil and initiallyLocked = true. Also, you don’t want to put the dobjFor(Lock) and dobjFor(Unlock) in the subContainer. Put those bits in the main ComplexContainer code. The ComplexContainer will take care of routing the commands to its subContainer.

Thanks once again for your rapid help. I will try out your suggestions ASAP.

The reason you’re getting a run-time error may be because Attachable is a mix-in class. As such, it has to be placed first in the class list when you’re defining the object.

Boy, do I feel like an idiot! I’m totally confused. I had no luck knowing where to place those changes you suggested. Now, when I compile and do a test run, I’m told that the room is completely dark. I removed that whole section of code that is in this post and everything that’s left works fine.

The TADS manuals seem to be great telling what you should but they leave something in telling you what you should not do.

Now, I have to think about what my next step should be.

RonG

If the room is suddenly dark, it might be because you’ve used the + notation to put the PC in the room, but now you’ve parked another object with no + above the code for the PC. This will put the PC in the other object, not in the room. That would be my bet.

ComplexContainers are among the more convoluted things in TADS (along with ActorStates, which can also get a bit snarly). Why not start by implementing the basic layout of your game and then, after that’s working, start adding more complex objects?

Also, BTW, indentation is totally optional in T3, but using it (in a consistent way) is a great way to help you troubleshoot your code.

Thanks for the comments. I had planned to do this game in a linear mode but, you’re right, I am making things too complex too soon. I’m going to do as you’ve suggested. You’re also very correct about the indentation. That will be taken care of.

RonG

I’m speaking from personal experience. The first time I tried to learn T3, I gave up. It was too complicated for me, or so I thought. The problem was, while working with the example game in the Getting Started Guide, I had decided that the player really ought to be able to look through the window into the cottage. I mean, looking through a window is pretty important, right? And you can do it in T3, but you’ll need to know about SenseConnectors and sightsize and Occluders and various other things.

So I tripped over my shoelaces a few times. When I came back to TADS the second time, I was still bothered by the problem of looking through a window, but I had more patience, and (with the help of a few power users, who were very patient) I managed to learn a bunch of stuff.

I know how you must have felt. I started working professionally on both the computer hardware and software in about 1965. I’ve worked on anything and everything you can think of and it was uphill all the way. I even went to Phoenix for a year to learn how to write code in machine language.

Now, like a big dummy, I’m starting all over again at 73 years of age. But I still love it! Will talk to you later.

RonG