 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
Mr B
Joined: 20 Mar 2003 Posts: 382
|
Posted: Wed Apr 26, 2006 12:04 pm Post subject: Limited Inventory |
|
|
Hullo folks,
I am currently approaching the near side of the back end of the development cycle for a game of mine (100% of enemy and attack graphics, 95% hero graphics, maptiles, enemy design, items, <10% plotscripting) and have come up against a bit of a snag.
I want to have a limited inventory, such that the hero can hold only 10-15 (haven't decided) unequipped items. This is rather important for the game balance, and has been in planning for quite some time. Unfortunately, I hadn't actually thought about how to implement it until a few days ago.
I would normally check to see how many of each item is in the inventory, but I have over 200 item slots to inspect. All of these checks would have to take place after each battle. If the inventory is too full, it will have to be completely checked each time the player attempts to leave the menu in order to make certain that sufficient items were thrown out.
Since I can rigorously check how many items are going into the inventory, I am tempted to just use a variable that increments and decrements. However, there is no way for me to decrement the variable, as the "throw out" button in the inventory does not call any scripts.
I really loathe the inefficiency of checking up on 200 potential items. Is there any other way of doing this?
Thanks in advance,
-B |
|
Back to top |
|
 |
Moogle1 Scourge of the Seas Halloween 2006 Creativity Winner


Joined: 15 Jul 2004 Posts: 3377 Location: Seattle, WA
|
Posted: Wed Apr 26, 2006 12:50 pm Post subject: |
|
|
Don't allow the player to throw away items? Or you could just custom-script the item menu. _________________
|
|
Back to top |
|
 |
Mr B
Joined: 20 Mar 2003 Posts: 382
|
Posted: Wed Apr 26, 2006 1:33 pm Post subject: |
|
|
Moogle1 wrote: | Don't allow the player to throw away items? Or you could just custom-script the item menu. |
In which case I'd need to check for the 200 items in order to populate the menu.
Of course, if I only show so many at a time, I might have to check only half in order to fill the screen.
Hmmm...what if I had an upper and lower limit variable that recorded the highest and lowest item ID #, and then only looked at the items between those numbers? Since I can see and control which items are going into the inventory it would be easy to expand the numbers, and I can reduce them whenever I check... |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Wed Apr 26, 2006 2:54 pm Post subject: Re: Limited Inventory |
|
|
Mr B wrote: |
I really loathe the inefficiency of checking up on 200 potential items. Is there any other way of doing this?
|
This is just a "for" loop. I don't think it will be a problem. Have you written any code that counts used slots yet? Was it actually slow? Or are you just afraid that it might be slow in theory? |
|
Back to top |
|
 |
Mr B
Joined: 20 Mar 2003 Posts: 382
|
Posted: Wed Apr 26, 2006 7:30 pm Post subject: |
|
|
Just slow in theory. My main worry about slowness is when the player needs to get rid of a few items in order to get below (or hit) the maximum allowable space. If the player destroys something, attempts to exit, is told to destroy something else, and the whole process repeats again, each time looking at 200 slots, it sure seems as if it would take a while. |
|
Back to top |
|
 |
Moogle1 Scourge of the Seas Halloween 2006 Creativity Winner


Joined: 15 Jul 2004 Posts: 3377 Location: Seattle, WA
|
Posted: Wed Apr 26, 2006 7:34 pm Post subject: |
|
|
Let's say you can only get one item at a time. (This may not be true, but the algorithm still holds.) You can make an array (0..15) of items that the player has when you check the inventory. Then, if you need to check for missing items, you only need to check the items indexed in the array. _________________
|
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Thu Apr 27, 2006 9:01 am Post subject: |
|
|
I'm not sure if this is what Moogle1 means, but here is my idea:
After any 'event', where the player may gain items, run a loop that checks for the items, and if the player has any of the item, store the item ID in a global variable. Then while they are choosing things to throw away, equip, etc., you only need to run a loop through your global variables to see if those item(s) are still there.
Also, make sure you have straight whether they are allowed to have 15 total items, or 15 different types of items (thus allowing 99 medicines).
Possible problem:
If you go by this route (more complicated than the normal 'for' loop script-wise, but probably more efficient...?), you will also need to store equipment in globals, so that the list is complete even if the player changes equipment while choosing what to do with their extra items. Or do you want them to be allowed to do this?
This makes me think that it might be nice to have a plotscripting commands to affect a player's items by referencing their slot in his or her item menu, and a command to 'sort', that is, to do whatever the engine does when the player chooses the 'arrange' thing on the item menu (or whatever it is called; I mean the thing that smushes the items together, eliminating blank space) |
|
Back to top |
|
 |
Mr B
Joined: 20 Mar 2003 Posts: 382
|
Posted: Thu Apr 27, 2006 2:30 pm Post subject: |
|
|
Yeah...these are some good ideas. I think that having an array for the inventory would be best. I will have to script my own (un)equip method as well as inventory management, but it should really do the trick.
Thanks for your help, everyone. |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Thu Apr 27, 2006 2:50 pm Post subject: |
|
|
Mr B wrote: | Just slow in theory. My main worry about slowness is when the player needs to get rid of a few items in order to get below (or hit) the maximum allowable space. If the player destroys something, attempts to exit, is told to destroy something else, and the whole process repeats again, each time looking at 200 slots, it sure seems as if it would take a while. |
Never worry about slowness in theory. Only worry about slowness in reality. Try it the "brute force" way, and if it is too slow, *then* post the code and we can help think of ways to make it faster.
If it is too slow, then probably the best easiest way to solve the problem is to add some new plotscripting commands. The existing inventory commands only let you think in terms of item name/IDs. There are no commands for thinking in terms of inventory slots.
Also, you know, hard-coding a feature into the OHR to allow the game designer to set inventory size limits would be great. I think that is the best solution-- and it is something that should really happen anyway, since the item code is in need of clean-up. |
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|