Re: Suspected bug in Shops

From: Jason Yarber (
Date: 06/10/02

> I looked in the shopping_list routine in shop.c, and found what I believe
> the problem to be.  There is a for loop that goes through all the objects
> the shopkeeper currently is carrying.  The first time through, the pointer
> last_obj is NULL, so this executes a special section of the code, which
> last_obj to the current object, and the count of that object to 1.  Note
> that we haven't set the "found" flag to true yet.  We continue looping.
> Lets assume that the shopkeeper has more of the same item - so the second
> and subsequent times around this for loop, since last_obj is no longer
> the first else clause will be executed.  But the first statement in this
> an if test to see if this object is the same as  the previous object, and
> so, all we do is increment the counter.  We still have not set "found"
> nor have we listed anything.
> What I believe is happenning is that since we never execute the code
> that actually lists the line showing the item and the quantity on hand
> (because the trigger for this is when we find a new item that is not the
> same as the last item).  This section also sets the flag "found".
> Once we have added up the total number of items (all of hte same type), we
> have not actually set this found flag.  Hence the program logic things
> there is nothing currently available.

Hmm, ok, without looking at the shop code, and just by going off what you
here, here's my advice for this situation.  I'm assuming that it's using 3
one int(for how many objects it has), one *char[](for the name of the
object), and one int[](for the price of the object).  Like I said, I'm not
looking at the code, i'm
just going to fly it here.  Here's what you can do to solve your problem.
At the top of the function, change the int[] to another *char[], for this
I'll call it *char2[], then after the variable defines, give the *char[]
variable a
value of "Item", and give *char2[] the value of "Price".  After that,
anywhere it
called upon int[], change it to *char2[], and where it sets int[] equal to
your gonna have to convert the numbers to ascii, i don't remember off hand
the c function for that was.  I know this explanation was a bit cryptic, and
i probably
should have grabbed a piece of code from shop.c to show you, but then again,
I don't
exactly know what your shop functions look like.  But what this does, is
starts the variables
off with a value, so that when it encounters that first object, it will
think it found a different
object, and will actually go through the code that sets found to true.  It
also sets up a neat little
header above the items.  There is probably a line in the code that does that
already, but if you use
this and it works, then you can comment that line out.  Good luck.

Jason Yarber

   | FAQ: |
   | Archives: |
   | Newbie List:   |

This archive was generated by hypermail 2b30 : 06/25/03 PDT