Two of my WIPs are either entirely or partially driven by a >GO TO [room] mobility system. The second one, which I just recently started working on, got me thinking that I should turn the idea into an extension (or at least a page on Hugo by Example). I haven't really perfected anything, but I'll share what I've got so far.
First off, before "hugolib.g" is included, I declare some new >GO grammar:
verb "go", "walk"
* DoGo
* "to"/"in"/"into"/"inside"/"through" anything DoGoTo
* "out" object DoGo
* "out"/"outside" DoExit
* anything DoGoTo
Now, since we're going to be giving rooms noun and adjective properties, making them refer-able, we'll replace the room class with something that redirects a lot of actions:
replace roomEDIT: It turns out the above is really bad code, as lots of verb routines (like DoGet) expect to have an object value, so Perform-ing them with no object actually makes you pick up the nothing object (and so on). Here is some better code (although it's kind of "blunt force"; maybe there's a more elegant solution):
{
type room
is static, light, open, known
before
{
object
{
if verbroutine = &DoGo, &MovePlayer,&DoLook, &DoGoTo
{
return false
}
object = 0
Perform(verbroutine)
return true
}
object DoLook
{
Perform(&DoLookAround)
}
}
}
replace roomWe'll also make an "exits" property that keeps track of which rooms are available from other rooms (in this game, >GO TO just works room-to-room; this is not intended to be a Magnetic Scrolls type >GO TO scenario).
{
type room
is static, light, open, known
before
{
object
{
if verbroutine = &DoMove,&DoGet, &DoDrop, &DoPutIn,
&DoEmptyOrGet, &DoGive, &DoShow, &DoWear, &DoTakeOff,
&DoEat, &DoDrink, &DoHit, &DoLookThrough, &DoLookUnder, &DoExit
{
"I didn't understand you. Try being more specific."
return true
}
elseif verbroutine = &MovePlayer,&DoLook, &DoGoTo
{
return false
}
elseif verbroutine = &DoGo, &DoEnter
{
Perform(&DoGoto, self)
return true
}
object = 0
Perform(verbroutine)
return true
}
object DoLook
{
Perform(&DoLookAround)
}
}
}
property exitsNow, our DoGoTo routine:
routine DoGoTo
{
if object = location
{
"You're already there!"
return false
}
if not FindObject(object, location)
{
if object.type = room
{
if InList(location,exits,object)
{
return MovePlayer(object)
}
else
{
if not location.cant_go
{
"You can't go that way."
}
return false
}
}
}
return Perform(&DoGo,object)
}
A "here" object to redirect things like >GO TO HERE to the current location:
object here_object "here"An example room:
{
noun "here"
before
{
object
{
Perform(verbroutine, location)
}
xobject
{
Perform(verbroutine, object, location)
}
}
in_scope you
is known
}
room STARTLOCATION "Start Location"
{
adjective "start"
noun "location"
exits pond, barn
}
So, that's basically it. An issue: one of the things my code does is make every room known so that MovePlayer works. If you still want a sense of discovery in your games, you could have DoGoTo automatically make rooms listed in the exits property known (so that rooms 2 connections away might still be a mystery).
Anyhow, I don't think the code is ready for HbE yet, but I thought people might find it interesting just the same. Plus, hey, this blog needs all of the posts it can get.