Page 1 of 1
Testing components' part_of "parent"
Posted: Thu Oct 25, 2012 4:41 pm
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?
Posted: Thu Oct 25, 2012 5:25 pm
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):
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:
(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
{
for (i=1; i<=parent(player).#reach; i++)
{
if Contains(parent(player).reach #i, p) or ! is the object part of an object inside the reach object
p = parent(player).reach #i ! is the object part of a reach object
{
return true
}
}
p = p.part_of
}
So yeah, let me know if that helps.
Posted: Thu Oct 25, 2012 6:36 pm
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:
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:
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.
Posted: Thu Oct 25, 2012 6:50 pm
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:
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:
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
{
part_of 0
}