The easiest way to fix your code would be with logic such as:
for (each affect on the object)
if ( this affect is the right one )
modify it
return
create a new affect and add it to the object
That is, move everything you have in the else block inside the for loop
outside of the for loop. If the right affect is found inside the for
loop, it will be handled and the function will return. So any code
after the for loop will be run if and only if no matching affect is found.
This is the place to create the new affect.
I saw another problem with your code after I wrote the previous reply.
In the code for creating an affect, there are lines like
"af_new->where = paf->where;". These will need to be changed. If no
matching affect is found, paf will not be pointing to anything useful
(with the change I suggest above, it will be NULL). You need to set
the variables to the right values (I'd have to dig into ROM a little
to figure out what the right values are, but you should be able to
figure it out) instead of copying from paf.
Dennis
On Tue, 7 May 2002, Matt Foltz wrote:
> Well I've been fooling with it all night, and I've yet
> to succeed in making it work right. The
> affect_enchant part works fine (go figure :P), but I'm
> not exactly sure what you mean to do for the other
> part. I understand why my logic is flawed, just not
> too sure what to do. I haven't touched any code in 3
> years, and this is the first project I'm tackling.
> -Matt Foltz
>
> > The second major problem you have is that your logic
> > is completely wrong.
> >
> > for (each affect on the object)
> > if ( this affect is the right one )
> > modify it
> > return
> > else
> > create a new affect and add it to the object
> >
> > The code as is will work correctly in exactly one
> > case: the obj index
> > has one affect, and it is not the one you're
> > changing. In all other
> > cases, it will do the wrong thing.
> >
> > You should not be creating a new affect for each
> > non-match you see. You
> > should create exactly one new affect if no matching
> > affect was found.
> >
> > Since your for loop returns if it finds the right
> > one, the code after
> > the for loop will never get run if the affect is
> > found. This is where
> > you want the code to create a new affect.
> >
> >
> > Dennis
> >
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Health - your guide to health and wellness
> http://health.yahoo.com
>
>