Wednesday, October 16, 2013

new old bug! (DoExit)

We've had some new eyes looking at Hugo code lately, and sometimes that's all it takes to discover a long-existing bug.  Don't really know how it didn't turn up before, but this person noticed that when the player is in a closed, openable, and enterable container, typing "OUT" would result in "Nothing is closed."

Initially, I was worried that this was due to the SetUpDirectionObjects routine not properly setting the object global to the out_obj object (since I still don't entirely trust how Perform uses that routine), but the problem turned out to be in DoExit itsellf (in fact, the out_obj doesn't really matter when DoExit is called since almost all applicable error messages will mention the parent of the player, if anything).

The problem turned out to be that the "so-and-so is closed" VMessage text was expecting the object global to exist, and DoExit wasn't properly defining it in that instance.  So, here's a version of DoExit where that is fixed:

replace DoExit
{
local p

#ifclear NO_OBJLIB
! >GO OUT winds up calling DoExit with object = out_obj, thanks to
! the direction-parsing code in Perform().  English ambiguities being
! what they are, we correct that interpretation of "out" here, and
! treat the command as a generic instruction to exit whatever
! container context we may be in.
if object = out_obj
object = nothing

if object = nothing or object = location
{
if player in location and out_obj in direction
{
word[1] = out_obj.noun
word[2] = ""
return Perform(&DoGo)
}
}
elseif object = d_obj and player in location
{
return Perform(&DoGo, object)
}
#endif

p = parent(player)

#ifclear NO_OBJLIB
if object and player not in object
#else
if object and player not in object
#endif
VMessage(&DoExit, 1)             ! "You aren't in that."
elseif p is openable, not open
{
object = p
VMessage(&DoLookIn, 1)           ! "X is closed."
}
else
{
if object = nothing
object = p
move player to location
if not object.after
VMessage(&DoExit, 2)     ! "You get out.."
}
return true
}

Of course, this will be added to future versions of Roodylib.