Dear all,
I got an nil object reference error. It appeared after I implemented a test verb to obtain items. The code is:
DefineLiteralAction(Mget)
execAction(){
local txt = getLiteral();
if(txt==‘chisel’){
chisel.moveInto(me);
“snap ”;
return;
}
“Unknown object. Known objects: Chisel.”;
return;
}
;
VerbRule(Mget)
(‘mget’) singleLiteral : MgetAction
verbPhrase = ‘mget (what)’
;
The runtime error doesn’t happen immediately after the “mget chisel” command but when I typ “i” (inventory) afterwards.
Any idea what the problem is, or what other information you need to be able to help me?
Thanks and kind regards,
Grues
johnnywz00
(John Ziegler)
February 11, 2025, 11:02pm
2
I haven’t tested anything or really examined your code, but I know that many bugs can appear when using moveInto
instead of moveIntoForTravel
. When you’re whisking objects through thin air and not through a simulated containment structure, you want moveIntoForTravel
. I can’t guarantee that’s it, but it’s still worth observing.
1 Like
johnnywz00
(John Ziegler)
February 11, 2025, 11:03pm
3
Also not sure if this has any bearing on the problem at all, but you’re probably better off implementing that verb as a TAction. You just need to set it to global scope in order to summon objects from anywhere in the game…
1 Like
John Ziegler:
moveIntoForTravel
Using moveIntoForTravel doesn’t change anything, error still happens.
Using a TAction instead of a LiteralAction brings up the same error when trying the initial command (“mget chisel”) already. That’s interesting, but being a n00b to TADS I can’t figure out the reason behind it.
johnnywz00
(John Ziegler)
February 12, 2025, 12:59am
5
Maybe you should just see if this premade debug verb works for you:
everything : object
lst {
if (lst_ == nil)
initLst();
return lst_;
}
initLst {
lst_ = new Vector(4100);
local obj = firstObj();
while (obj != nil) {
if(obj.ofKind(Thing))
lst_.append(obj);
obj = nextObj(obj);
}
lst_ = lst_.toList();
}
lst_ = nil
;
DefineTAction(Purloin)
cacheScopeList() {
scope_ = everything.lst();
}
;
VerbRule(Purloin) ('purloin'|'pn') dobjList
: PurloinAction
verbPhrase = 'purloin/purloining (what)'
;
modify Thing
dobjFor(Purloin) {
verify {
if(isHeldBy(gActor))
illogicalNow('{You/he} {is} already holding it. ');
}
action {
mainReport('{The/he dobj} pop<<isPlural ? '':'s'>> into your hands.\n ');
gSetSeen(self);
if(ofKind(Hidden) && !discovered)
discover;
sightPresence = true;
moveIntoForTravel(gActor);
moved = true;
}
}
;
You should be able to type pn chisel
from any location in the game and end up with it in your inventory.
1 Like
jbg
(jbg)
February 12, 2025, 1:03am
6
Is chisel
a Thing
, and if so can you just do a >TAKE CHISEL
and see if it exhibits the same behavior?
2 Likes
jbg
(jbg)
February 12, 2025, 1:11am
7
For whatever it’s worth, this compiles and runs fine for me:
#charset "us-ascii"
#include <adv3.h>
#include <en_us.h>
startRoom: Room 'Void' "This is a featureless void. ";
+me: Person;
+chisel: Thing '(wood) chisel' 'chisel' "A wood chisel. ";
versionInfo: GameID;
gameMain: GameMainDef initialPlayerChar = me;
DefineLiteralAction(Mget)
execAction() {
local txt;
txt = getLiteral();
switch(txt) {
case 'chisel':
"Done. ";
chisel.moveInto(me);
break;
default:
"Unknown object <q><<txt>></q>. ";
break;
}
}
;
VerbRule(Mget)
'mget' singleLiteral: MgetAction
verbPhrase = 'mget/mgetting (what)'
;
Transcript:
Void
This is a featureless void.
You see a chisel here.
>mget chisel
Done.
>i
You are carrying a chisel.
>
2 Likes
That produced the same error, but it made me do some extended tests, which eventually lead me to the solution, and boy was it a simple one…
…the damn chisel had its name in quotes instead of apostrophes. That was all!
Thanks for taking care of me once more! Strictly appreciated!
1 Like