I had a good theory about sorting and inventory (by which i mean moving all the empty spaces so you dont leave gaps when you use an item),
if there was an empty space it would become the item below it and the one below would be emptied.
it worked once but when i tried to repeat it for all the inventory slots it messed up. Shame because it was a good idea.
Most sorting routines use a loop and an index variable. The loop iterates through as many steps as there are current inventory slots (this includes the empty ones.) Lets say you have 100 inventory slots...1-50 have items..51-99 are empty and then 100 has an item. Have the loop iterate 100 times, and for each iteration check that inventory slot. If it has an item, increment the Index variable by 1. If not, don't touch the index variable. Also, make sure you check if the current item slot being checked is == to the index variable. If not, then copy the current item slot into the slot # of the index variable.
Using the numbers above, the index would increase by 1 for the first 50 slots...then while the loop is iterating through the empty slots 51-99, the index variable won't be touched and it'll still be 50. When it gets to item 100, it checks the index variable to see if that is at the same slot that the loop is at...since it isn't it copies the item at the current loop iteration to the slot referenced by the index variable. Then you need to increment the index variable by 1.
Current Project: Undertaking the design of my mammoth RPG. Utilizing all of the knowledge gained while coding the now defunct "Shadow Reign".
AndyUK: a better way is the way SNES RPGs all used to do it. There are a number of memory positions each corresponding to an item, with the value being the number of that item in your posession. Then there was a similar array of items, only each value represted the position in the inventory of that item. The cheap way to move items up would then be to not move them up, instead simply having "ITEM x 0" as some games did it, otherwise shifting the array values only when the last instance of an item has been consumed.
Some games, however, lacked the second array. Instead each item had a specific position in the inventory, but when you had zero, they aren't displayed and the next item is moved up (when the list is generated, not its actual position).
Edit:
SoS may have covered some of that, bud damned if I'm reading that essay of his.
-whip out a text file to remind you of what everything would be, example:
-I want my
Severed Big Toe to be item # 1
Severed Big Toe - 1
Big Whackin' Shoe - 2
Lysol - 3
Bucket of Shrimp - 4
(after you figure out everything you want in the game, give it a number. Get it?)
-After that go
Cond.
o Start of level
Even.
o Load INI to filename "inventory"
-Make your guy get something now... like a Severed Big Toe!
Cond.
o Player presses whatever wherever to get big toe
Even.
o Set INI group to "items"
o Set INI item to whatever number you wrote severed big toe down as in your writing file... (remember it was 1)
o Set INI value to "1" (1 means you have it)(which means when u didnt have the toe,
it's value was 0)(Get it so far?)
This is you getting the toe, then it is loading the toe thru INI, then by setting it to 1, it's saying you picked it up.
Theres a start. But I Just Realized That This Would Only Work For An RPG With A Certain Amount Of Items. Like Unlocking Items. I Play Too Much Zelda. Crap.
I'd be willing to write a book article covering many different inventory systems and possible implementation methods if there is some serious interest. Anyone?
Edited by the Author.
Current Project: Undertaking the design of my mammoth RPG. Utilizing all of the knowledge gained while coding the now defunct "Shadow Reign".
I will write it Jay, but after thinking about it for a while I'm going to wait until I get my current group of engines completed. Upon completion I'll be writing a series of articles that will document not only how each engine works but also how to utilize it to create your own offshoot games. If I stop now I might lose momentum and never complete them. So for now, all of my efforts are going to go towards them.
Sorry for making an offer that I'm now suspending.
Current Project: Undertaking the design of my mammoth RPG. Utilizing all of the knowledge gained while coding the now defunct "Shadow Reign".
Definitely not a bad system Andy. It all depends on what you're looking for. The only problem with that system is it's impossible to implement multiple bundles of the same item. You couldn't have two "groups" of 99 heal potions for example.
It all depends on what your game needs, of course.
Current Project: Undertaking the design of my mammoth RPG. Utilizing all of the knowledge gained while coding the now defunct "Shadow Reign".