Greets! I was trying to write a simple game and encountered a problem with global-locals elements. Here's a code snippet.
"Rooms"
<ROOM PILL-ROOM
(DESC "Strange Room")
(LOC ROOMS)
(GLOBAL WOODEN-DOOR)
(LDESC "The room looks like it's been unhabbited for a long time.")
(EAST TO CIRCULAR-HALL)
(WEST TO HALL IF WOODEN-DOOR-F ELSE
"A big wooden door blocks your way. It´s closed.")
(FLAGS ONBIT LIGHTBIT)>
"Objects"
<OBJECT WOODEN-DOOR
(DESC "Wooden door")
(SYNONYM DOOR)
(ADJECTIVE WOODEN)
(LOC LOCAL-GLOBALS)
(ACTION WOODEN-DOOR-R)
(FDESC "There is a big wodden door.")
(SIZE 50)>
Now, the door is not reachable from the room. You try to execute an action on it and it doesn't work.
I read the parser.zil code, routine FIND-ONE-OBJ. It does match with the GLOBAL-LOCAL object
WOODEN-DOOR, but it fails when it tries to check whether that GLOBAL-LOCAL is in that room or not.
It does access the room P?GLOBAL property, but whatever the code gets from that property, seems to not
be properly read. The same code is seen in the routine "GLOBAL-IN?".
I'm not sure if it should work or not. I haven't been able to fully understand it's behavior, so I'm looking
for a little bit of guidance. Maybe GLOBAL-LOCALS wasn't tested and the code is not right. Or maybe
it is me using zilf the wrong way.
Any help is appreciated.
Thanks in advance,
March
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2012-07-12
Ok, a friend and me found the thing. The table of local globals saves the id of the objects as bytes, not as words, and were being accessed as words.
Here's the reimplementation of the GLOBAL-IN routine and the FIND-ONE-OBJ that uses this new GLOBAL-IN (instead of copypasting the code):
<ROUTINE GLOBAL-IN?(O R "AUX" H GMAX X)<OR <SET H <GETPT .R ,P?GLOBAL>><RFALSE>><SET GMAX <-<PTSIZE .H>1>><REPEAT ((X 0))<COND
(<==?<GETB .H .X>.O>;<TELL "ROOM has a matching GLOBAL" CR><RTRUE>)(<IGRTR? X .GMAX><RFALSE>)>>><ROUTINE FIND-ONE-OBJ (YTBL NTBL "AUX" A N F G H GMAX X P)<SET A <GET .YTBL 1>><SET N <GET .YTBL 2>><IF-DEBUG <TELL "[FIND-ONE-OBJ: adj=" N .A " noun=" N .N "]" CR>>;"check abstract/generic objects"<OBJECTLOOP I ,GENERIC-OBJECTS
<COND (<REFERS?.A .N .I><SET F.I><RETURN>)>><AND .F<RETURN .F>>;"check for light"<COND (<NOT <FSET?,HERE ,LIGHTBIT>><COND (<NOT <SEARCH-FOR-LIGHT>><TELL "It's too dark to see anything here." CR><RFALSE>)>)>;"check location"<OBJECTLOOP I ,HERE
;<TELL "Room Loop object is currently " D .I CR><COND (<REFERS?.A .N .I><SET F.I>;<TELL "F is now set to " D .F CR><RETURN>);"if any items are surfaces, open containers, or transparent containers, search their contents"(<COND (<OR <FSET?.I ,SURFACEBIT>;"open container"<AND <FSET?.I ,OPENABLE><FSET?.I ,OPENBIT>>;"always open container"<AND <FSET?.I ,CONTBIT><NOT <FSET?.I ,OPENABLE>>>;"transparent container"<AND <FSET?.I ,CONTBIT><FSET?.I ,TRANSBIT>>>;<TELL D .I " is a container." CR><SET F<CONTAINER-SEARCH .I .A .N>>;<TELL "Back in main FIND-ONE-OBJ loop and F is " D .F CR><AND .F<RETURN>>;<RETURN>)>)>><AND .F<RETURN .F>>;"check inventory"<OBJECTLOOP I ,WINNER
<COND (<REFERS?.A .N .I><SET F.I><RETURN>);"if any items are surfaces or open containers, search their contents"(<COND (<OR <FSET?.I ,SURFACEBIT>;"open container"<AND <FSET?.I ,OPENABLE><FSET?.I ,OPENBIT>>;"always open container"<AND <FSET?.I ,CONTBIT><NOT <FSET?.I ,OPENABLE>>>;"transparent container"<AND <FSET?.I ,CONTBIT><FSET?.I ,TRANSBIT>>>;<TELL D .I " is a container." CR><SET F<CONTAINER-SEARCH .I .A .N>>;<TELL "Back in main FIND-ONE-OBJ loop and F is " D .F CR><AND .F<RETURN>>;<RETURN>)>)>><AND .F<RETURN .F>>;"check global objects"<OBJECTLOOP I ,GLOBAL-OBJECTS
<COND (<REFERS?.A .N .I><SET F.I><RETURN>)>><AND .F<RETURN .F>>;"check local-globals"<OBJECTLOOP I ,LOCAL-GLOBALS
<COND (<REFERS?.A .N .I>;<TELL "FOUND OBJ in LOCAL-GLOBALS - now checking room" CR>;<PROG ()<TELL "I IS SET TO "><PRINTN .I><TELL CR>><AND <GLOBAL-IN?.I ,HERE><SET .F.I><RETURN>>)>><AND .F<RETURN .F>>;"no match";"TO DO - Search through containers in rooms to see if I-matching NPC is there for 'does not seem to be here' message"<OBJECTLOOP I ROOMS
<OBJECTLOOP J .I<COND (<REFERS?.A .N .J><SET .P .J>;<TELL "No match - P is " D .P CR><COND (<FSET?.P ,PERSONBIT><TELL D .P " does not seem to be here." CR ><RFALSE>)>)>>><TELL "You don't see that here." CR><RFALSE>>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Greets! I was trying to write a simple game and encountered a problem with global-locals elements. Here's a code snippet.
Now, the door is not reachable from the room. You try to execute an action on it and it doesn't work.
I read the parser.zil code, routine FIND-ONE-OBJ. It does match with the GLOBAL-LOCAL object
WOODEN-DOOR, but it fails when it tries to check whether that GLOBAL-LOCAL is in that room or not.
It does access the room P?GLOBAL property, but whatever the code gets from that property, seems to not
be properly read. The same code is seen in the routine "GLOBAL-IN?".
I'm not sure if it should work or not. I haven't been able to fully understand it's behavior, so I'm looking
for a little bit of guidance. Maybe GLOBAL-LOCALS wasn't tested and the code is not right. Or maybe
it is me using zilf the wrong way.
Any help is appreciated.
Thanks in advance,
March
Ok, a friend and me found the thing. The table of local globals saves the id of the objects as bytes, not as words, and were being accessed as words.
Here's the reimplementation of the GLOBAL-IN routine and the FIND-ONE-OBJ that uses this new GLOBAL-IN (instead of copypasting the code):
This is now working.