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 / Array Based Inventory system

Author
Message
GunnerWolf
11
Years of Service
User Offline
Joined: 21st Apr 2013
Location:
Posted: 22nd Apr 2013 03:15
Hi, I'm currently working on an inventory system for my RPG, it's a Text RPG, so not too much data is required, however, I was wondering, how (If at all possible) I could create an array of say, 100 items, and each item has a string and 5 integers assigned to it, so for example, if items(1) is a sword, it would be the following:

I'm aware that may not be the correct code to do that, but it shows what I mean, so then a sword would be:
["Sword",0,0,2,0,0]
the 5 mod ints are added to their respective stats while the item is equipped, for example, if some cursed armour has:
["Cursed Armour",-10,0,0,5,0]
then wearing it would decrease your max hp by 10, but increase Defence by 5
The reason I want to use an array is because the only other way I can think of doing it would be with a function sort of like this:

And adding an 8 line if statement for every single item.

Thanks in advance for any help.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd Apr 2013 22:29
You'll want to create a User-Defined Type (UDT). And instead of allocating the array for 100 items, use dynamic lists. This will allow your array to grow and shrink to the number of items you currently have. Then you can make a function for adding new items to the array.




"You're all wrong. You're all idiots." ~Fluffy Rabbit
GunnerWolf
11
Years of Service
User Offline
Joined: 21st Apr 2013
Location:
Posted: 24th Apr 2013 04:42
That looks really good, seems like a great way to handle it, thanks for the help, now I can continue with my game
GunnerWolf
11
Years of Service
User Offline
Joined: 21st Apr 2013
Location:
Posted: 24th Apr 2013 19:11
Is there any way to get an array index from one of the values? eg if Sword is one, is there any way to get the index of sword from the string "Sword"?
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 24th Apr 2013 21:41
Quote: "Is there any way to get an array index from one of the values?"

Only by searching for it like this.


Login to post a reply

Server time is: 2024-11-23 15:34:45
Your offset time is: 2024-11-23 15:34:45