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?
Testing components' part_of "parent"
Moderators: Ice Cream Jonsey, joltcountry
-
- Posts: 2256
- Joined: Mon Apr 29, 2002 6:23 pm
- Location: Milwaukee
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:
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):
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:
So yeah, let me know if that helps.
Checking for a component (from within object's description code):
Code: Select all
if self.part_of
Code: Select all
if self.part_of and self.part_of is <attribute>
Code: Select all
run self.part_of.long_desc
So you'd want (not that you'd do this):
Code: Select all
if self.part_of
run self.part_of.long_desc
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
}
-
- Posts: 151
- Joined: Fri Jul 09, 2010 8:59 am
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.Roody_Yogurt wrote: Checking if a component has an attribute:Code: Select all
if self.part_of and self.part_of is <attribute>
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
Code: Select all
if knob.part_of is hidden
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: So you'd want (not that you'd do this):Code: Select all
if self.part_of run self.part_of.long_desc
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.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:
Thank you, Roody. That helps a lot.
-
- Posts: 2256
- Joined: Mon Apr 29, 2002 6:23 pm
- Location: Milwaukee
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: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:Code: Select all
if knob.part_of = cabinet
Code: Select all
if knob.part_of is hidden
Code: Select all
object knob
{
part_of 0
}