Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Need help with Inventory system!

Author
Message
Rwilson
21
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 10th Sep 2003 01:14
At this moment, the code within the code window is how I'm doing the inventory within my RPG. Right now, it's only capable of handling Weapons for reason I shall soon reveal. Really, it works quite well, It displays, adds, and equips correctly, but for the moment, only with weapons. Orignally, this was due to the fact that I just wanted to concentrate on one thing at a time. Now, I've realized that the code is so wrapped about the weapons, I've found myself unable to find a way to insert armor. The original way I was going to do it was use a flag of sorts to determine whether or not it was a Weapon, Armor, or Item, but then I realized As I was typing this code here:

if keystate(28) = 1 and WeaponsList(CurItem).TypeFlag = 1

that the only way this would work was if the armor was within the WeaponsList array, which would be impossible (I think) to do since there are two (and eventually three) seperate User Defined Types, and as I understand it, there can only be one UDT per array. And for the same reasons, I can't create a Single array for all inventory for the same reasons. I've hit a roadblock, and I'd deeply appreciate any attempts to help me get around it! If you need any more information concerning the program to help solve this query, just ask!

With Regards
Ryan Wilson
orv
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: Chicago, IL
Posted: 10th Sep 2003 21:23
Why not generalize things a little more by just simply changing your weapons array to be called your inventory array?


if keystate(28) = 1 and InventoryList(CurItem).TypeFlag = 1

your type flag would determine WHAT the inventory item is.

Based on your TypeFlag element's value, your program could determine which elements to check or update.

you might like to have constants for your type flag too! Ex:

INV_WEAPON
INV_ARMOR
INV_FOOD
INV_MEDICINE

you might think there are some items for example which are only used by weapons in you UDT, so what? just don't use them as an array element.

Finally, a note: when designing data structures, try to generalize as much as you can get away with for the whole structure, ex:
Inventory Structure as opposed to weapon structure, a little planning can increase the flxblity as power of the structure and make programming easier!

I hope this helps!
ChipOne
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Canada
Posted: 10th Sep 2003 22:13
orv's suggestion gets you almost the whole way there.

only thing missing now is that curItem has to become:
curWeaponIndex
curArmorIndex
curFoodIndex
(etc.)

this allows you to be equipped with a weapon AND armor at the same time. but he's right, there's no necessity that requires all be seperate. keep in mind that you will have to check for type no matter what you're doing. if it gets complex, you might even just declare three additional arrays of integers that only list the indices of their members in the inventory array.

for example, you might have:
dim weaponsList(0) as integer

everytime you add a weapon to your inventory array, you would add the inventory index to your weapons list. this double-referencing takes up little memory and adds many conveniences.

cheers.

-= i only do what my rice krispies tell me to do =-
Mussi
21
Years of Service
User Offline
Joined: 27th Jan 2003
Location: Netherlands
Posted: 10th Sep 2003 23:17
maybe you could use something like this:



hope that helps you out

Specs: AMD Athlon 1800, 256 DDRRam 266mhz, 80GB HD 7200rmp U133, Geforce 4 Ti4400 128mb ddr sdram

Login to post a reply

Server time is: 2024-09-20 21:34:50
Your offset time is: 2024-09-20 21:34:50