npc nil object reference

Help!

I have another bruse on my head from hitting the keyboard.

I have a female npc, me and object x all in the same room. When I give the command ‘npc, give me x’ I get a ‘nil object reference’ error.

I can ask for and give the object to the npc but not command the npc to take it or give it to me. I would expect the library to give me the default response, ‘she refuses your request’ or ‘she does not respond’.

Any ideas anybody?

Which TADS version are you using? A backtrace (from a debug build of the game) would also be useful.

I had a problem rather like this last month, and it was because I was misusing CommandTopic. If you post the code you’re using to handle the command, I’m sure someone can spot the problem.

Thanks Jim, I thought that as well but I am not using any comandTopic, I did a copy/paste and stripped down the npc with only the topics for the objects and a default askfor, give and ask topics, when I entered the command again I got the askForTopic response for the object, so no ‘nil object reference error’ but still not right. I will post the code soon when I have time. Thanks again!

I found the problem! I was using a text string to match the askForTopic instead of a game object.

While that was easy enough to fix, the problem remains with the way the game deals with askFor and give topics, I can add a check to the askForTopic to see if she has the object and give a suitable response.
I thought that when you use format ‘lady, give me object x’ it would be treated as a command and give the default response ‘she refuses your request’, or am I expecting too much from the library?

Start Room

This is the starting room.

You see an object x, a dummy, and an object z here.

The lady is standing here.

hello
Hello!

lady, take dummy
The lady refuses your request.

lady, take object x
The lady refuses your request.

lady, take object z
The lady refuses your request.

lady, give me object x
No, you gave me this!

lady, give me object z
I’m sorry, but I have no idea what you are talking about.

lady, give me dummy
dummy askfor topic response.

give her object x

(first taking the object x)
Well! thank you very much!

give her object z

(first taking the object z)
No thank you.

give her dummy

(first taking the dummy)
No thank you.

ask for object x
No, you gave me this!

ask for object z
I’m sorry, but I have no idea what you are talking about.

ask for dummy
dummy askfor topic response.

[code]#charset “us-ascii”
#include <adv3.h>
#include <en_us.h>

versionInfo: GameID
IFID = ‘0215fb68-ce0f-9d81-a32e-d537ee51a875’
name = ‘Your New Game Title’
byline = ‘by Your Name’
htmlByline = ‘by
Your Name

version = ‘1’
authorEmail = ‘Your Name your-email@host.com
desc = ‘Put a brief “blurb” about your game here.’
htmlDesc = ‘Put a brief “blurb” about your game here.’
;

gameMain: GameMainDef
initialPlayerChar = me
;

startRoom: Room ‘Start Room’
"This is the starting room. "
;

  • objectX : Thing ‘object x’ ‘object x’
    ;

  • objectY : Thing ‘dummy’ ‘dummy’
    ;

  • objectZ : Thing ‘object z’ ‘object z’
    ;

  • me: Person
    ;

ladyFraser : Person ‘lady fraser’ ‘lady’ @startRoom
“lady fraser desc”
isHer = true
;

  • DefaultAskTellTopic, ShuffledEventList
    [
    ‘Really? Well I am rather busy…’,
    'You seem to find ’ + gTopicText + ’ very interesting… ',
    ‘Yes well… whatever…’
    ]
    ;

  • AskForTopic @objectY
    "dummy askfor topic response. "
    ;

  • AskForTopic @objectX
    "No, you gave me this! "
    ;

  • GiveTopic @objectX
    topicResponse
    {
    "Well! thank you very much! ";
    objectX.moveInto(ladyFraser);
    }
    ;

  • DefaultAskForTopic
    "I’m sorry, but I have no idea what you are talking about. ";
    ;

  • DefaultGiveTopic
    "No thank you. ";
    ;

  • fraserTalking : InConversationState
    nextState = fraserWaiting
    ;

++ fraserWaiting : ConversationReadyState
isInitState = true
;

+++ HelloTopic
"Hello! ";
;
+++ ByeTopic
"Goodbye. ";
;[/code]

This one you can solve by creating a flag in ladyFraser, such as .playerHasGivenMeObjX, initially set to nil, and updated when the player gives her ObjX.

Then in the text of the askFor topic, give it one of these << playerHasGivenMeObjX ? "Indian-giver! I’m keepin’ it! " : "What ObjX? ">>

–I’m going from memory on the syntax there, but something to that effect would work.

Conrad.

Commands in this format:

Are automatically rewritten as:

Thanks to giveMeToAskFor. This seems to have bitten all of us at one point or another.

Thanks conradcook, I will give that a try.

Also thanks to bcressey, experience and hindsight are wonderful…