more nil obj ref errors with adv3lite

I have a one-character-one-room “game” (for lack of a better word) using adv3Lite.

When I enter Look at XXX, I get nil object reference errors for some random selection of XXX words. (Also appears to fail with Examine, though I haven’t tried as many words.)

For example…

…but…

…generates the nil object reference error. (And, I just noticed, that’s with starts; I had initially tried stars, which also generates the nil obj ref. Now I see it also barfs on starts, which I fat-fingered when I tried to get text to copy into this message).

Other words I tried that failed…

dollar
coin
skull
pound
atm
wheel

…to name a few, while these succeeded…

wallet
pocket
display board
key

I wondered if somehow the Workbench was getting confused by objects I had defined in previous games I’ve been working on recently (just worked through the adv3lite tutorials, plus my own ATM money machine) but I see objects from all of those efforts on both lists. And, I trashed my entire test-bed game folder and created a new one, which shouldn’t have any baggage from passed coding efforts.

The game is simplicity itself, just about as basic as I can make it…

#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 <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
;

streetCorner: Room 
    '<font color="green">Street Corner</font>' 'street corner'
    "Corner of the street. "
;
// harry, main character
harry: Thing 'Harry;;man' @streetCorner
    ""
    isHim = true
    globalParamName = 'harry'
    isFixed = true   
    proper = true
    ownsContents = true
    person = 3   
    contType = Carrier   
;

Jerry

So, I changed the player char from “harry” to “me” and that seems to have cleared up the problem.

It appears related to the other nil object reference problem I had, and which Eric advised sticking with “me” as the player object for now. Seems there is a playerChar defined in the library code that Eric says is not needed and just seems to lurk in the shadows waiting to through out a nil object reference or two every now and then.

When the player is “me” I no longer get the nil reference.

I did, btw, apply the patch Eric offered in that other thread but still got the nils until I changed my code to “me”.

Jerry

That’s almost certainly the case. The problem can arise at any time the game is doing scope calculations, though why it should occur with the particular list of words you found I’m not sure (this could have something to do with Mercury’s spell-checker, which produces certain other odd effects - Mike Roberts sent me a patch for that yesterday but I haven’t had time to apply it yet. The problem occurs because in one place the World object uses its own playerChar property as an argument to a method that calculates scope, and I’d defined World.playerChar statically as me (at some point in the distant past, presumably as a quick fix to some other problem) and then forgotten about it. Every else I’d replaced World.playerChar with gPlayerChar (which is the correct solution).

I’m surprised you still got the nil object reference errors after applying the patch though; that causes a slight doubt in my mind whether there may be something else going on here. If I get a chance later today I’ll take a look at it. But looking at my earlier post in the other thread I see I didn’t make it as clear as I meant what the patch should be, since I missed a line of text out. You need to replace:

playerChar = me

With

playerChar = gPlayerChar

On the World object in parser.t.

An even better patch (and the change I’ve actually applied for the next release), is to locate the line in the scope() method of the World object near the top of the parser.t file and replace the line that reads;

  scope_ = s = Q.scopeList(playerChar);

With

  scope_ = s = Q.scopeList(gPlayerChar);

You should then be able to comment or delete the playerChar property altogether.

If that doesn’t work then the run-time errors you’re seeing must have another cause.

UPDATE: I’ve now tried running your code against the version 0.7 library, and I get the same errors you do, but they go away when I apply the suggested patch (playerChar = gPlayerChar instead of playerChar = me), so this does look like a manifestation of the same error as before. I’m not surprised that this error should cause a whole raft of run-time errors, even though I don’t immediately know why your getting them with some nouns and not others.

Eric:

Sorry, my error. I did apply the patch you recommended—or thought I did—by making this change in parser.t in C:\Program Files (x86)\TADS 3\lib\adv3Lite…

// playerChar = me playerChar = gPlayerChar
…and I still got nil obj ref. Then (smack me upside the head) I discovered I had not applied the patch in the library files actually used to build the game. When I made the change to the library within Workbench and recompiled, it worked as expected, no nil reference on “Look at stars” when the main player is harry, not me. So, hooray, your earlier patch did work, thank you very much.

I have also just now applied the new patch you have recommended, so that World in parser.t now begins like this…

[code]World: PreinitObject
/*
* Get the list of objects in scope
*/
scope()
{
local s = scope_;
// JF—April 29, 2013
// Q.scopeList(playerChar) changed to Q.scopeList(gPlayerChar) on
// advice from Eric Eve, https://intfiction.org/t/more-nil-obj-ref-errors-with-adv3lite/5323/1
// in following…
if (s == nil)
scope_ = s = Q.scopeList(gPlayerChar);
// scope_ = s = Q.scopeList(playerChar);

    return s;
}

/* cached scope list */
scope_ = nil

/* the current player character object */
// JF--April 28, 2013
// next line commented out and replaced by the line that follows, 
// to fix nil object reference failure, per Eric Eve, 
// https://intfiction.org/t/nil-object-reference-error-when-using-adv3lite/5317/9
// playerChar = me
playerChar = gPlayerChar

...etc. 

[/code]

Jerry