Calling class properties
Posted: Sat Aug 21, 2010 1:42 pm
I'm surprised and confused by Hugo's behavior in regard to a class that I designed for my current project.
In my game, I have a lot of outdoor locations, many of which are separated from each other a ways. So I frequently add messages to be displayed when leaving a room in a given direction before the room description of the destination room, describing how the player hikes down this or that path, etc. The simple way to accomplish this was to put the messages in the direction_to properties, and that worked fine. But I'm using these travel messages frequently enough that I decided to design a custom room class to support them.
A "journeyroom" is a room that has twelve extra properties to hold the messages for going in any of compass directions (pluss in/out, up/down) and a before property to print the message before proceeding to the rooms direction property. The properties are all labelled "going_(direction)". The before property has a section for each going_ property that looks like this:
(The default value for going_n and all the other going properties is "").
And this works great... except that it prints the message twice in a row! Looking at the Debugger, it seems that Hugo is calling the individual room's before property that it inherited from the journeyroom class, and then it calls the parent class's before property separately.
The only time I explicitly tell Hugo to print the going_direction property is in the line "print self.going_n/s/e/w/etc" above. But when I comment this line out, it works perfectly, printing the travel message just once, and then a new line, and then the name and description of the destination room. I'm really confused! How does Hugo know to call, and to print the going_dir property unless I tell it to? The only explanation I can fathom is that the condition if self.going_n = "" calls the object's before property, and then the print self.going_n was an explicit instruction to print the class's property. But wait a minute... the class's property is only "", so that doesn't make sense either.
I'm glad that it's basically doing what I want, but I don't understand, and I don't feel that good about it.[/b]
In my game, I have a lot of outdoor locations, many of which are separated from each other a ways. So I frequently add messages to be displayed when leaving a room in a given direction before the room description of the destination room, describing how the player hikes down this or that path, etc. The simple way to accomplish this was to put the messages in the direction_to properties, and that worked fine. But I'm using these travel messages frequently enough that I decided to design a custom room class to support them.
A "journeyroom" is a room that has twelve extra properties to hold the messages for going in any of compass directions (pluss in/out, up/down) and a before property to print the message before proceeding to the rooms direction property. The properties are all labelled "going_(direction)". The before property has a section for each going_ property that looks like this:
Code: Select all
if self.going_n = "" ! no message provided
{
return false ! continue on
}
else
{
print self.going_n
}
And this works great... except that it prints the message twice in a row! Looking at the Debugger, it seems that Hugo is calling the individual room's before property that it inherited from the journeyroom class, and then it calls the parent class's before property separately.
The only time I explicitly tell Hugo to print the going_direction property is in the line "print self.going_n/s/e/w/etc" above. But when I comment this line out, it works perfectly, printing the travel message just once, and then a new line, and then the name and description of the destination room. I'm really confused! How does Hugo know to call, and to print the going_dir property unless I tell it to? The only explanation I can fathom is that the condition if self.going_n = "" calls the object's before property, and then the print self.going_n was an explicit instruction to print the class's property. But wait a minute... the class's property is only "", so that doesn't make sense either.
I'm glad that it's basically doing what I want, but I don't understand, and I don't feel that good about it.[/b]