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 / How to inventory?

Author
Message
Levanthus
21
Years of Service
User Offline
Joined: 17th Apr 2003
Location: Cumbria, UK
Posted: 15th Jul 2010 00:43 Edited at: 18th Jul 2010 19:38
How would one go about making an Inventory?
I'd like to have something similar to that of Broken sword where you have a bar at the top that has you inventory items in it, and when you click on an image it "sticks" to the pointer and then when you click on the interactive object it "uses" it.

I'm guessing a DIM would be used to create the inventory to start with and when you pick up the item it gets stored in the DIM?

it's mostly the storing of the items that i need the help with at the moment although i'm still also puzzling over how you would make the items appear in the bar in the order you pick them up.

I'm not overly farmilliar with the DIM command so i'm not entirely sure how it works or IF it's the command i'd need to use.

Any help would be great thanks

I can see from your smile, you're not here for the sunset

Windows 7 64 bit, AMD Phenom II x4 Black edition, 4 GB Ram, Radeon HD 4650, 540 GB HDD
Devonps
15
Years of Service
User Offline
Joined: 5th Nov 2009
Location: Nottingham
Posted: 15th Jul 2010 01:15 Edited at: 15th Jul 2010 01:23
One possible way to approach this is as two different but similar/linked tasks. For example I would use a TYPE declaration to hold my inventory items such as:



Then do a DIM ObjectsInInventory(?) as inventory

where ? equals the maximum number of objects that can be held in the inventory.

Then I would have a function that would query the inventory type and extract and display the object image.

As for the ordering requirement - as the player picks up an object just add the object id & image id to the array, for that you could use a command such as ARRAY INSERT AT TOP ObjectsInInventory() and loop through in what ever order you desired.

Hopefully I've made myself clear, if not let me know,

Steve.

Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 15th Jul 2010 11:28 Edited at: 15th Jul 2010 11:29
Generally there is a master list of all items in the game with all the attributes associated to each item (weight, power, type of weapon/armor). Much like Devonps' UDT above.

The actual inventory on the player is usually just a simple one dimensional array (like DIM Inventory(20) ) that is used as a reference to the master list of items.

Like if you had a Broadsword of Power (item number 231) in your simple player inventory you only have the number 231. When you want to know what graphic to use, the kind of sword and what it does you look at item number 231 on the master list array.

To really learn about arrays it's easier to read TDK's Tutorials first... his tutorials will answer many of your questions:
http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

Levanthus
21
Years of Service
User Offline
Joined: 17th Apr 2003
Location: Cumbria, UK
Posted: 15th Jul 2010 17:22 Edited at: 18th Jul 2010 19:38
ok what does 'TYPE' do?

and if i make say

DIM inventory(99)

how do i then write the items to the array when i pick the item?
I looked at the tutorial and i'm still a little confused by it, yes it explains WHAT they are and HOW they work, but i couldn't glean exactly how to USE them.

So say i have an item and i call it HEX-KEY and i have a .bmp to go with that called HEX-KEY.bmp. I would somehow need to put into the array that the two items are connected? but then also i'd need some way to identify that it is the object i need for a certain "job" as it were?

I'm sorry if i seem ignorant or whatever, but arrays confuse the hell out of me.

I can see from your smile, you're not here for the sunset

Windows 7 64 bit, AMD Phenom II x4 Black edition, 4 GB Ram, Radeon HD 4650, 540 GB HDD
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 15th Jul 2010 18:21
Quote: "I'm sorry if i seem ignorant or whatever, but arrays confuse the hell out of me."


They may, but once you understand them, you'll love 'em.


Here i'll answer this for you.

Quote: "ok what does 'TYPE' do?"



Here, look at this code i'm using for my rpg:







....Then from there, each Item() has the same properties:






Cool,huh? Any Questions, just ask. Happy to help.

Levanthus
21
Years of Service
User Offline
Joined: 17th Apr 2003
Location: Cumbria, UK
Posted: 18th Jul 2010 14:28 Edited at: 18th Jul 2010 19:38
So as i Understand it i need, for example



that much seems easy enough to understand, so now i have 100 empty "Slots" yes? Now say i pick up "HexKey" as an item how would i ten define that to go into one of the "slots"

would something like


Then "Define" the object itself? Where i expect 1000 is the image number that you would load at some point?

then maybe use a function to create it like


i duuno if what i wrote is utter Rubbish or not, i'm just trying to understand it all

I can see from your smile, you're not here for the sunset

Windows 7 64 bit, AMD Phenom II x4 Black edition, 4 GB Ram, Radeon HD 4650, 540 GB HDD
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 18th Jul 2010 18:44 Edited at: 18th Jul 2010 18:47
Quote: "that much seems easy enough to understand, so now i have 100 empty "Slots" yes? Now say i pick up "HexKey" as an item how would i ten define that to go into one of the "slots""


Actually you would have 101 elements because Items(0) is the first element. And "end type" is one word ENDTYPE.

Quote: "then maybe use a function to create it like"


You almost got it. When you make the UDT and the DIM statement like this:


Your telling Darkbasic that you want the array Items() to use the UDT InvStuff data structure. So when you want to add information to the array you use Items() not InvStuff.

Like this:


And when you want to use ARRAY INSERT AT BOTTOM if you start the array with DIM Items(100) when it sees the ARRAY INSERT AT BOTTOM command it'll make the array larger as if you dimensionalized it as DIM Items(101) and add if you don't specify which element to use when defining the array ( Items().ItemName = ) it's added to the end of the array (at 101). You need to dimensionalize the array with DIM Items() so you don't start with any blank entries in the array.

Try this code with dimensionalizing the array at 2:


Run the above code to see blank entries from 0 to 2. Then erase the 2 in DIM Items(2) as InvStuff and run it again. You should see that the only element in the array is the item added.

By the way... even though Christopher Lloyd is the greatest actor on Earth that signature is way too big. The limit for graphical signatures on the the Darkbasic forums is 600x120.

Levanthus
21
Years of Service
User Offline
Joined: 17th Apr 2003
Location: Cumbria, UK
Posted: 18th Jul 2010 19:36 Edited at: 18th Jul 2010 20:19
Ok cool, i think i'm starting to get it.

What is the difference in using
array insert at bottom
and
array insert at top

does it make a big difference with how things work?

How would i check to see if a certain object in IN the array also, like if i had picked up a key is there a way to chack that it is IN the array in order to use it with a door for example?

Also would an array be used to like display the images along the bottom of the screen or would that be done in a different way?

I can see from your smile, you're not here for the sunset

Windows 7 64 bit, AMD Phenom II x4 Black edition, 4 GB Ram, Radeon HD 4650, 540 GB HDD
Levanthus
21
Years of Service
User Offline
Joined: 17th Apr 2003
Location: Cumbria, UK
Posted: 18th Jul 2010 23:49
OOh i think i may have managed it!



seems to work for me....

Now my problem is getting the images on the screen

I can see from your smile, you're not here for the sunset

Windows 7 64 bit, AMD Phenom II x4 Black edition, 4 GB Ram, Radeon HD 4650, 540 GB HDD
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Jul 2010 02:50 Edited at: 19th Jul 2010 02:54
Quote: "What is the difference in using
array insert at bottom
and
array insert at top

does it make a big difference with how things work?"


Yes, it's a big difference. ARRAY INSERT AT TOP will move all elements down one and insert a blank element at the top of the array (zero).

Quote: "How would i check to see if a certain object in IN the array also, like if i had picked up a key is there a way to chack that it is IN the array in order to use it with a door for example?"


A simple FOR/NEXT loop would do the trick. Not quite like you had it though... it doesn't have to be that complicated. When you use a FOR/NEXT loop you use a variable that increases on every loop. FOR t=1 to 100 means that t=1 the first loop, t=2 the second loop and so on till it's 100 and the FOR/NEXT loop automatically exits.



Quote: "Also would an array be used to like display the images along the bottom of the screen or would that be done in a different way?"


Yes you can since you added the image number to the array. You just use the array to PASTE the images on the screen. This creates 9 images (numbers 1 to 9) and PASTEs them to the screen by each item in the array. The x and y coordinates determine where that graphic is going to be on the screen. x is horizontal and y is vertical.




For inventory it's really better to avoid adding and deleting elements in the array. If you dimensionalize the array at 19 and if your character can only hold 20 items at a time there's no need to delete any element because weather or not they are holding 20 items does not negate the fact that the max is 20 and you have an array to fit the max already. Notice on the code snip above. When there wasn't an item to show (zero) it didn't place an image on the screen.

Levanthus
21
Years of Service
User Offline
Joined: 17th Apr 2003
Location: Cumbria, UK
Posted: 19th Jul 2010 08:22 Edited at: 19th Jul 2010 08:23
AHHH yes, i ALMOST had it with the images... I'm pretty sure i'm starting to get a hang of these arrays.... finally. Thank you all for your infinite patience with explaining it to me.

All that remains for my inventory now is to figure out how to select the items to use them i'm thinking maybe using the scroll wheel to cycle through it... BUT not right now... I've been up all day/night messing with this thing and it's now 6:21 am... maybe time for sleeps

I can see from your smile, you're not here for the sunset

Windows 7 64 bit, AMD Phenom II x4 Black edition, 4 GB Ram, Radeon HD 4650, 540 GB HDD
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 22nd Jul 2010 21:50
Quote: "
All that remains for my inventory now is to figure out how to select the items to use them i'm thinking maybe using the scroll wheel to cycle through it... BUT not right now... I've been up all day/night messing with this thing and it's now 6:21 am... maybe time for sleeps"


Dont Code yourself into a corner! If your img are all 32 by 32(or any perfect square like 16x16,64x64), you could divide the mouse position by 32 and compare it to the images position, or you could use sprites and evalualte the collision data......Just thoughts...

luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 23rd Jul 2010 20:54
This is how i do it.
First video :
http://www.youtube.com/watch?v=Uv54l5W972g&NR=1

Second video :
http://www.youtube.com/watch?v=qiMFBf2UG8I

It's not finished yet, but pretty close.Inventory type of the game you mention is very simmilar to my RPG with the diference that yours expect to use items on interactive objects anything else is the same.Actually my system needs just a function to handle drags on interactive objects to fit your needs.

You can ask me about how i did suff in it, because at this moment i don't consider to share the code.That's something sentimental for me knowing what it cost me to write this.One day it's gonna be free for comunity.

In short i can say that this system involves arrays, UDT , file writes and reads , text wrapping , sprite managment.

Cheers!

Coding is My Kung Fu!
And My Kung Fu is better than Yours!
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 23rd Jul 2010 22:25 Edited at: 23rd Jul 2010 22:27
I made one a while ago, pics:





Though I ended up scrapping it for a vertical scroll inventory so I can have all the information available to me instead of having to position the mouse over the icon to see it. Wonder if I can find it again, then I hopefully can help out.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Jul 2010 10:21
Here's the coding technicalities:

Asset Management

Scaleable Assets and Templates

luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 31st Jul 2010 13:13
Asset Management is where i learned from then my inventory has born. Very helpful stuff, anyone who want to do inventory must read it.

Coding is My Kung Fu!
And My Kung Fu is better than Yours!

Login to post a reply

Server time is: 2024-11-23 11:28:18
Your offset time is: 2024-11-23 11:28:18