I'm trying to have the clothing class check if it is hidden or
not, which will change if it is listed or not. I thought I could just
override the existing isHidden with a check, but I'm apparently not getting
it quite right. Most of the other code is donated and I've never been good
at lists.
What I'm really aiming at is that if a higher layer is being worn, the
lower layers are hidden. This would require the check to find the
highest layer and then set the flag on the other clothing items. I'm not
at all sure how to set up a variable to compare the current item with
the last one. I know I need at least one other variable here, but I'm
getting stumped.
The code I have is below, can somebody help me figure this out. I think I'm close,
but something is still messed up, I keep getting a stack overflow. If I
haven't got this completely messed up I might actually think that I'm
getting the idea about how to check a list. I'd really appreciate some
help.
class topItem: clothingItem
isTop = true /* hats, etc., for checking purposes */
layer = 1 /* for layer checking to use with hiding */
;
modify clothingItem
isHidden =
{
local i, o, p, list; /* int, obj, previous, list */
list := self.location.wearing; /* problem if it's not worn!? */
for (i := 1; i <= length(list); i++) /* loop through the clothing */
{
o := list[i]; /* current object */
if (o = list[0]) /* first in list has nothing to be compared to */
return(nil);
else if (o.layer < p.layer)
return(true);
}
p := o; /* set previous to val of current for next check */
}
;
Thanks
Tom
You might want to check out the clothing library on the archive:
http://www.ifarchive.org/if-archive/programming/tads/examples/clothing.zip
[..]
>What I'm really aiming at is that if a higher layer is being worn, the
>lower layers are hidden. This would require the check to find the
[..]
Note, though, that wearing a jacket doesn't conceal your pants. So you
may have to consider areas as well as layering. Anyway, I'd suggest
something like:
modify clothingItem
isHidden =
{
local i, len;
if (not self.isworn) return nil; // never hidden if worn
len := length(self.location.contents);
for (i := 1; i <= len; i++)
{
// if my layer is less than this object's layer, I should be hidden
// (unless the object is this object, of course)
if (self.layer < self.location.contents[i].layer &&
self <> self.location.contents[i])
return true;
}
// if we never returned true, return nil, because nobody's hiding us.
return nil;
}
You could in theory change that if statement to
if (self.layer < self.location.contents[i].layer &&
self <> self.location.contents[i] &&
self.area = self.location.contents[i].area)
and it would handle objects only hiding those in the same area,
assuming you set the areas correctly.
>Tom
--
Dan Shiovitz :: d...@cs.wisc.edu :: http://www.drizzle.com/~dans
"He settled down to dictate a letter to the Consolidated Nailfile and
Eyebrow Tweezer Corporation of Scranton, Pa., which would make them
realize that life is stern and earnest and Nailfile and Eyebrow Tweezer
Corporations are not put in this world for pleasure alone." -PGW