Help with inventory for RPG
Author |
Message |
PesticideUse
|
Posted: Wed Apr 01, 2009 9:50 pm Post subject: Help with inventory for RPG |
|
|
I'm making a Final Fantasy-esque RPG and need help with my inventory. Not so much the coding, i should be able to do that, but ideas.
I want my items to rearrange every time i use an item, so for example:
I use item 3, item 4 moves to the item 3 slot and item 5 moves to item 4 slot.
So far what I've got planned is to create an "Empty Slot" item that will be in every slot to start with, then once you get items they take that spot. Once you use an item it will change to an empty slot. Then using a for structure i would check if the item below any item was an empty slot if it was it would move down.
This seems like it would take a lot of space and be time consuming.
If anyone can think of an easier way please explain I'd post the code but its so long and convoluted it would take forever to understand (I started before i knew to organize and comment. )
Thanks all for any help |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dusk Eagle
|
Posted: Wed Apr 01, 2009 10:38 pm Post subject: Re: Help with inventory for RPG |
|
|
First of all I'm assuming you want to transfer item three in your example to the last element of your array, not just simply destroy item 3 altogether. In that case, I see nothing wrong with the way you've planned it.
PesticideUse wrote: Once you use an item it will change to an empty slot.
This should take only one line of code.
PesticideUse wrote: Then using a for structure i would check if the item below any item was an empty slot if it was it would move down.
Since we've already transferred the value of item 3 to the end of the list, we don't care about overwriting it. Then, in a for loop you copy item 4 into item 3, item 5 into item 4, etc. There is no need to check if the item below is an empty slot as our logic guarantees that all we will be overwriting is a duplicate value. This should only take three lines of code, and one of them is an "end for".
When you're done this, you may find that you have item 3 twice at the end of your array. Since I am not aware of any built-in way of assigning a NULL value to a variable, there are a couple of things you could do about this.
One is to resize the array down by one to delete the duplicated value and then resize it up by one immediately after. However, I am not sure how effecient this is.
The other is to simply have a value that you will always count as null within your array. For instance, if your array is an array of strings, simply place a value of "NULL" into that final element.
I hope I have made myself clear enough above, but if you need code I can provide it. I think you should try doing this yourself first though. |
|
|
|
|
|
PesticideUse
|
Posted: Thu Apr 02, 2009 6:03 pm Post subject: Re: Help with inventory for RPG |
|
|
sweet thank you very much for the advice, im glad it wont be too long |
|
|
|
|
|
saltpro15
|
Posted: Thu Apr 02, 2009 7:13 pm Post subject: Re: Help with inventory for RPG |
|
|
you will want to read this |
|
|
|
|
|
|
|