FAQ Search Memberlist Usergroups
Jolt Country Forum Index
Register Profile Log in to check your private messages Log in
Log in Log in

Testing components' part_of "parent"

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Jolt Country Forum Index -> Hugo's House of Horrors
View previous topic :: View next topic  
Author Message
Bainespal



Joined: 09 Jul 2010
Posts: 151

PostPosted: Thu Oct 25, 2012 4:41 pm    Post subject: Testing components' part_of "parent" Reply with quote

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?
Back to top
View user's profile Send private message
Roody_Yogurt



Joined: 29 Apr 2002
Posts: 1993
Location: Milwaukee

PostPosted: Thu Oct 25, 2012 5:25 pm    Post subject: Reply with quote

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:
if self.part_of


Checking if a component has an attribute:
Code:
if self.part_of and self.part_of is <attribute>


You just can't write code that assumes a part_of value, like:
Code:
 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:
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:

        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.
Back to top
View user's profile Send private message AIM Address
Bainespal



Joined: 09 Jul 2010
Posts: 151

PostPosted: Thu Oct 25, 2012 6:36 pm    Post subject: Reply with quote

Roody_Yogurt wrote:

Checking if a component has an attribute:
Code:
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:
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:
if knob.part_of is hidden


Roody_Yogurt wrote:

So you'd want (not that you'd do this):
Code:
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.
Back to top
View user's profile Send private message
Roody_Yogurt



Joined: 29 Apr 2002
Posts: 1993
Location: Milwaukee

PostPosted: Thu Oct 25, 2012 6:50 pm    Post subject: Reply with quote

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:
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:
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:

object knob
{
   part_of 0
}
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Jolt Country Forum Index -> Hugo's House of Horrors All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001 phpBB Group

Theme by Kage Musha - RPG Garden

Copyrights and trademarks are all of the belonging company. No copyright Infringement intended