Calling class properties

This is a discussion / support forum for the Hugo programming language by Kent Tessman. Hugo is a powerful programming language for making text games / interactive fiction with multimedia support.

Hugo download links: https://www.generalcoffee.com/hugo
Roody Yogurt's Hugo Blog: https://notdeadhugo.blogspot.com
The Hugor interpreter by RealNC: http://ifwiki.org/index.php/Hugor

Moderators: Ice Cream Jonsey, joltcountry

Bainespal
Posts: 151
Joined: Fri Jul 09, 2010 8:59 am

Calling class properties

Post by Bainespal »

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:

Code: Select all

if self.going_n = "" ! no message provided
        {
          return false ! continue on
        }
        else
        {
          print self.going_n
        }
(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]

Johnny
Posts: 36
Joined: Sat Oct 15, 2005 4:30 pm
Location: Humble, Texas

Post by Johnny »

You could try 'if &self.going_n = ""'.

Bainespal
Posts: 151
Joined: Fri Jul 09, 2010 8:59 am

Post by Bainespal »

Thanks for the suggestion. I haven't been around because I just started college and I've also been betatesting someone else's IF game.

Anyways, I still don't understand what the issue is. Using "&self.going_n" instead of "self.going_n" doesn't make a noticeable difference in the output. I've tried to follow what the Hugo's doing when it executes that code in the debugger, but it didn't help me in any tangible way.

Interestingly, "#self.going_n" is closer to working than the other two. It only prints the string stored in the property once, but then it prints a new line and a period. The new line and the period are also printed when I have "self.going_n" or "&self.going_n", after the property is printed twice, with only a line break between them. I have no idea where the mysterious period comes from. I can't even find any reference to the period and line break when looking at the executed code in the debugger.

So, I'll just do what works and comment out the explicit print statement in my code. It may not be elegant, and I don't know why it works. But it works, and I don't have to worry about it. :)

Roody_Yogurt
Posts: 2180
Joined: Mon Apr 29, 2002 6:23 pm
Location: Milwaukee

Post by Roody_Yogurt »

Yeah, I've found that something like "if self.going_n" is going to execute going_n if object.going_n exists, so all you really need is:

Code: Select all

if self.going_n
return false

Post Reply