File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Item Inventory

 
Ty Wood
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Ignore the horrid fill-paint please. ;D


Anyway, I'm trying to set up an inventory like system. I have two methods, find an empty slot, and find the slot that has item X:




As you can see from the picture though, it puts the item three times, not once. I've been looking through this and haven't found any rhyme or reason to it.
Help? >_<
 
Paul Clapham
Sheriff
Pie
Posts: 20191
26
MySQL Database
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are lines 14 and 15 in findSlot supposed to be executed for each column, or just once over all? If the latter, then move them from where they are (inside the loop which is executed once per column) to a place where they will be executed only once.
 
Ty Wood
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah woops. That would account for it. Oh wow, what a foolish mistake. Dx

Thanks!

*walks away in shame with tail between legs
 
Paul Clapham
Sheriff
Pie
Posts: 20191
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to me you should just return when you've found the array entry you're looking for, instead of using those boolean flags. Some people don't approve of using "return" anywhere except at the end of the method, but I'm not one of those people. You will have noticed that the boolean flags can go wrong. However if you're writing programs for one of those people, then by all means stick with the boolean flags.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic