This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Game Development and the fly likes Item Inventory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Item Inventory" Watch "Item Inventory" New topic
Author

Item Inventory

Ty Wood
Greenhorn

Joined: Mar 12, 2012
Posts: 12


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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Mar 12, 2012
Posts: 12
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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
 
subject: Item Inventory
 
Similar Threads
Not Compiling > problelm
Highlighting a JTable cell on a successful search for a value entered in a textfield.
Could you please help me?
HELP Need to convet code to be non static (I believe)
Simple prob