nil object reference error when using adv3Lite

I have encountered a couple of problems using the adv3lite library, one serious, one minor.

Serious first:

I have created a simple test-bed environment with a single character who has a wallet inside a pocket.

If I look in the wallet without first looking in the pocket, game play halts and the debugger displays a TADS Runtime Error message box that says nil object reference.

If I restart the game and look in the pocket first, then look in the wallet, the game responds correctly.

Minor problem second:

The game does not define a “me” actor. I renamed the main character “harry”. The game runs correctly, but when I build it in the Workbench, I get the following debugger warnings…

I get no such debugger warnings in a full (non-lite, a.k.a. heavy) TADS3 environment that does not have a “me” character.

Here is the Lite implementation of the game in its entirety…

[code]#charset “us-ascii”

#include <tads.h>
#include “advlite.h”

versionInfo: GameID
IFID = ‘47ca87f1-2d0e-4b54-a776-2bc128e30927’
name = ‘TADS 3 Test Bed’
byline = ‘by Jerry Ford’
htmlByline = ‘by
Jerry Ford

version = ‘1’
authorEmail = ‘Jerry Ford jerry.o.ford@gmail.com
desc = ‘Test bed for experimenting with TADS 3 Lite.’
htmlDesc = ‘Test bed for experimenting with TADS 3 Lite.’
;

gameMain: GameMainDef
initialPlayerChar = harry
;
// harry, main character
harry: Actor ‘Harry;;man’ @streetCorner
“”
isHim = true
globalParamName = harry
;

  • pocket: OpenableContainer, Fixture ‘pocket;;pocket’
    "Harry’s pocket. "
    initiallyOpen = nil
    ;

// harry’s wallet
++ wallet: Container ‘wallet;worn leather;wallet’
"A worn leather bifold wallet. "
contentsListed = nil
;

streetCorner: Room
‘Street Corner’ ‘street corner’
"Corner of the street. "
roomFirstDesc = "Corner of the street. There is an ATM in the building’s
wall. "
;
[/code]

Jerry

I wasn’t able to reproduce this error with the setup you described. The code I tested with was:

+ me: Thing 'you'      
    isFixed = true    
    proper = true
    ownsContents = true
    person = 2   
    contType = Carrier    
;

++ pocket: Container 'pocket'
;

+++ wallet: Container 'wallet'
;

++++ banknote: Thing 'banknote'
;

And the response I got was:

>i
You are carrying a pocket (in which is a wallet).

>look in wallet
In the wallet you see a banknote.

Can you supply more details of your code? I tried making the wallet and then the pocket an OpenableContainer but that didn’t generate an error either. I also tried making the pocket part of a coat worn by the player character, and still no error.

You’re right that this problem isn’t serious, in that it won’t affect the running of the game in any way, but you’re also right that ideally you shouldn’t get the warnings, so I’ve fixed this for the next release.

I can’t give you any more details about the code than was originally posted—the code provided there is all there is.

However, it looks like the two problems—no “me” and the nil object reference—are one and the same.

When I change “harry” to “me” (and comment out the “globalParamName=harry” line), the game compiles with no warnings and looking at the wallet before opening the pocket works as expected—“there is no wallet here.”

If only fails when there is no “me”.

Jerry

I tried replacing the me object with a harry object, but I still didn’t get the error. Where is the original listing of your code posted (specifically, in adv3Lite version)?

In the initial post, at the top of this thread.

For convenience, here it is again…

#charset "us-ascii"

#include <tads.h>
#include "advlite.h"

versionInfo: GameID
    IFID = '47ca87f1-2d0e-4b54-a776-2bc128e30927'
    name = 'TADS 3 Test Bed'
    byline = 'by Jerry Ford'
    htmlByline = 'by <a href="mailto:jerry.o.ford@gmail.com">
                  Jerry Ford</a>'
    version = '1'
    authorEmail = 'Jerry Ford <jerry.o.ford@gmail.com>'
    desc = 'Test bed for experimenting with TADS 3 Lite.'
    htmlDesc = 'Test bed for experimenting with TADS 3 Lite.'
;

gameMain: GameMainDef
    initialPlayerChar = harry
;
// harry, main character
harry: Actor 'Harry;;man' @streetCorner
    ""
    isHim = true
    globalParamName = harry
;
+ pocket: OpenableContainer, Fixture 'pocket;;pocket'
    "Harry's pocket. "
    initiallyOpen = nil
;

// harry's wallet
++ wallet: Container 'wallet;worn leather;wallet'
      "A worn leather bifold wallet. "
      contentsListed = nil
;

streetCorner: Room
    '<font color="green">Street Corner</font>' 'street corner'
    "Corner of the street. "
    roomFirstDesc = "Corner of the street. There is an ATM in the building's
        wall. "
;

Eric:

I may have narrowed it down a bit…

When I use your code for harry, his pocket and his wallet, I get the same results you do. It works.

But when I change the pocket to be an OpenableContainer instead of the Container as you defined it, I get the nil object reference again.

Here’s my modified code…

[code]#charset “us-ascii”

#include <tads.h>
#include “advlite.h”

versionInfo: GameID
IFID = ‘47ca87f1-2d0e-4b54-a776-2bc128e30927’
name = ‘TADS 3 Lite Test Bed’
byline = ‘by Jerry Ford’
htmlByline = ‘by
Jerry Ford

version = ‘1’
authorEmail = ‘Jerry Ford jerry.o.ford@gmail.com
desc = ‘Test bed for experimenting with TADS 3 Lite.’
htmlDesc = ‘Test bed for experimenting with TADS 3 Lite.’
;

gameMain: GameMainDef
initialPlayerChar = harry
;
streetCorner: Room
‘Street Corner’ ‘street corner’
"Corner of the street. "
roomFirstDesc = "Corner of the street. There is an ATM in the building’s
wall. "
;
harry: Thing ‘you’ @streetCorner
isFixed = true
proper = true
ownsContents = true
person = 2
contType = Carrier
;

  • pocket: OpenableContainer ‘pocket’
    // initiallyOpen = nil
    ;

++ wallet: Container ‘wallet’
;

+++ banknote: Thing ‘banknote’
;[/code]

Changing the class of pocket from OpenableContainer to Container makes it work again; changing back to OpenableContainer makes it fail.

Jerry

Sorry! I should have seen that; comes of trying to do thing in too much of a hurry!

But, I tried your code and I still didn’t get a run-time error. What I got was:

Street Corner

Corner of the street. 

>look in wallet
Harry sees no wallet here.

>look in pocket
(first opening the pocket)
In the pocket Harry sees a wallet.

>look in wallet
Harry sees nothing interesting in the wallet. 

Which is what I’d expect.

I did see some things wrong with your code, however.

  1. adv3Lite has no initiallyOpen property (and in any case an OpenableContainer starts out closed by default).
  2. The globalParam name should be a string, not an object; i.e. globalParamName = ‘harry’

But none of these problems should cause a run-time error with the code you’ve quoted (or with the updated code you’ve just quoted).

It’s possible that this is due to changes I’ve made to the library since version 0.7 (which I assume is what you’re using), but otherwise I’m stumped, since I seem unable to replicate your error with your code!

Okay, thanks. I will accept that whatever is wrong on my end has been fixed in a later update to the library, and, yes, I have what looks to be 0.7 (adv3Lite07.zip).

Is that the current distribution or can I get a more recent release?

Jerry

I tried running your code with the 0.7 version of the library, and I indeed reproduced your run-time error. It turns out I inadvertently fixed the error in the course of getting rid of those warnings you told me about in an earlier post in this thread! The fix is in Parser.t, in the World object, in which the line:

playerChar = me
playerChar = gPlayerChar

At least, that fixes it for now. In the next version of the library I’ll do away with the playerChar property of World altogether, since it’s pretty much redundant except as a vehicle for causing this sort of problem! In the meantime I’d recommend either applying this patch or sticking with me as the player character object, otherwise you’ll probably run into a whole lot more run-time errors.

Good catch on your part!

Version 0.7 is the latest current distribution. You can find a more recent development build at https://github.com/EricEve/adv3lite.git, but that’s not guaranteed to be stable.