Testing components' part_of "parent"

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

Testing components' part_of "parent"

Post by Bainespal »

I'm not looking for specific code right now. I'm trying to think through what coding strategies I might use for Hugo Comp.

I will want to have a class of nearly-identical objects. All these objects will inherit from the component class. In their class definition, description properties will need to vary depending on whether or not the object that any particular one of these components is attached to with the part_of property has a given attribute.

Is Hugo even aware internally of what object a component's part_of property points to? Is there any way to check this in conditions?

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

Post by Roody_Yogurt »

I'm not entirely sure what you're asking here, so I'll write a couple things:

Checking for a component (from within object's description code):

Code: Select all

if self.part_of
Checking if a component has an attribute:

Code: Select all

if self.part_of and self.part_of is <attribute>
You just can't write code that assumes a part_of value, like:

Code: Select all

 run self.part_of.long_desc 
(well, you can, but the debugger will rightfully complain whenever part_of equals zero)

So you'd want (not that you'd do this):

Code: Select all

if self.part_of
      run self.part_of.long_desc
Another thing to be aware of is there is an extra layer of complexity if your game has components-of-components. loafingcoyote's and my CheckReach fix has the following code to keep such things in scope:

Code: Select all

        local p
	p = obj.part_of
	while p
	&#123;
	for &#40;i=1; i<=parent&#40;player&#41;.#reach; i++&#41;
	&#123;
     if Contains&#40;parent&#40;player&#41;.reach #i, p&#41; or ! is the object part of an object inside the reach object
          p = parent&#40;player&#41;.reach #i ! is the object part of a reach object
		&#123;
			return true
		&#125;
	&#125;
	p = p.part_of
	&#125;
So yeah, let me know if that helps.

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

Post by Bainespal »

Roody_Yogurt wrote: Checking if a component has an attribute:

Code: Select all

if self.part_of and self.part_of is <attribute>
That might be enough, for my purpose. I was not aware that a construct like "self.part_of is scenery" is legal code. I find that very interesting.

Still, I might want to explicitly write a condition dependent on the identity of the "part_of" object. Using the logic of "self.part_of is scenery", perhaps something like this, checking to see whether the knob is part of the cabinet:

Code: Select all

if knob.part_of = cabinet
And just to be sure that I understand, I know that the knob is part of the cabinet and I want to find out whether the cabinet is hidden:

Code: Select all

if knob.part_of is hidden
Roody_Yogurt wrote: So you'd want (not that you'd do this):

Code: Select all

if self.part_of
      run self.part_of.long_desc
I would rather just put a condition in the new class's long_desc (and possibly short_desc, etc.) that prints different text depending on what object the component is part of, or whether the object that the component is part of has a given attribute.
Roody_Yogurt wrote: Another thing to be aware of is there is an extra layer of complexity if your game has components-of-components. loafingcoyote's and my CheckReach fix has the following code to keep such things in scope:
That's interesting. I probably won't need to use the fix, though. I don't think I'm going to need components of components.

Thank you, Roody. That helps a lot.

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

Post by Roody_Yogurt »

Bainespal wrote:Using the logic of "self.part_of is scenery", perhaps something like this, checking to see whether the knob is part of the cabinet:

Code: Select all

if knob.part_of = cabinet
And just to be sure that I understand, I know that the knob is part of the cabinet and I want to find out whether the cabinet is hidden:

Code: Select all

if knob.part_of is hidden
Yup, those will work. If it helps, remember that "knob.part_of" is just short for writing "knob.part_of #1", so it's referring to the object (or lack of object) at:

Code: Select all

object knob
&#123;
   part_of 0
&#125;

Post Reply