Tutorial Downloads

File Size
algorithm.png384KB
Array based inventory.capx83KB

Translations

Know another language? Translate this tutorial!

Stats

2,028 visitors
46.7K page views
1,542 translation visitors
20K translation page views

Array-based inventory

Favourite 62 favourites
Tutorial written by WaltanOriginally published on 7th, July 2013 - 5 revisions

Hello everyone. I saw a couple of tutorials about making inventory and decided to share with you my way of making it.

I warn you that English is not my native language and in writing this tutorial, I used a translator. So if you found a grammatical error or a violation of the logic of the text, feel free to notice me.

Concept

This is how our inventory will work:
We need Array with 2 lines height and %how-many-inventory-slots-you-want% width.
In first line we will keep item's ID and in the second one - number of it.

Note, that our ID is not Construct 2 objects UID. You need to come up with this numbers by yourself. For example for item "Apple" we can assign ID = 1 and for item "Coin" ID = 2.

When you will click on inventory slot you need to save information about this slot to continue work. For this we need to create 3 variables:
startslot = id of start inventory slot
startitem = id of item in this slot
startnumber = number of this items
You may be asking yourself. Why, if there is an object in a cell, his number is 0 instead of 1.
Actually it does not matter. You'll see it down the tutorial.

After you have selected the required slot you need to select slot where you want to shift your item.
For this we need 3 more variables:
endslot
enditem
endnumber
After this, you just need to change the values ​​in the array by using created variables.

    Inventory.at(startslot,0) → Inventory.at(endslot,0)
    Inventory.at(startslot,1) → Inventory.at(endslot,1)
    Inventory.at(endslot,0) → Inventory.at(startslot,0)
    Inventory.at(endslot,1) → Inventory.at(startslot,1)

In fact, we did what we needed. We now turn to the practice.

Share and Copy this Tutorial

You are free to copy, distribute, transmit and adapt this work with correct attribution. Click for more info.

Comments

2
Robin Sommer 7,631 rep

Hero! I'm gonna make one right now. :D

Sunday, July 07, 2013 at 11:01:37 AM
1
Waltan 7,875 rep
Hero! I'm gonna make one right now. :D
quoted from Robin Sommer

I hope you do not get confused in my bad English %)

Sunday, July 07, 2013 at 11:04:20 AM
1
Lordshiva1948 38.7k rep

Nice one I will start making mine soon

Sunday, July 07, 2013 at 12:06:58 PM
1
Waltan 7,875 rep

I just found a little bug in my algorithm with tx variable. (3rd page)
Check it if you got problems with it.

Sunday, July 07, 2013 at 1:39:38 PM
0
sosensible 9,546 rep

dont need it yet but this will defenetily come in handy

Sunday, July 07, 2013 at 3:22:23 PM
1
SergioRM 6,849 rep

This is really good.
Thank you!

Sunday, July 07, 2013 at 10:25:33 PM
1
AbelaNET 14.6k rep

Thanks for sharing

Monday, July 08, 2013 at 10:27:11 PM
1
Zebra 1,457 rep

Thanks you so much for this!! (and sorry for my englisch)
I followed your tutorial, but I don't know how to add another item in the inventory.
When I try to do your example of "inventory efficiency", new items replace the ones that are already in the inventory, I can't place them in the empty slots.

Friday, July 12, 2013 at 11:26:56 AM
2
Waltan 7,875 rep
Thanks you so much for this!! (and sorry for my englisch)
I followed your tutorial, but I don't know how to add another item in the inventory.
When I try to do your example of "inventory efficiency", new items replace the ones that are already in the inventory, I can't place them in the empty slots.
quoted from Zebra

Here you go. goo.gl/A16f8 Download this .capx of "inventory efficiency". I made comments for you. All you need is in "Control system" group.

Friday, July 12, 2013 at 12:32:35 PM
1
Joannesalfa 27.8k rep

This is really efficient, actually I'm wondering how to substract an item when it's used?

I would like to know if you improve this when an item is used, it should be destroyed when value is 0 or -1

Saturday, July 13, 2013 at 8:36:34 AM
2
Waltan 7,875 rep
This is really efficient, actually I'm wondering how to substract an item when it's used?

I would like to know if you improve this when an item is used, it should be destroyed when value is 0 or -1
quoted from Joannesalfa

As I said in tutorial (end of page 3) it checks if number of this item > 0.
So, for example, if you will subtract 1 every time when you right click on slot, when value in array at this slot will = 0, you also should to erase data about item ID.

Check this .capx: goo.gl/A16f8 ("Tutorial" group)

I also updated "inventory efficiency" example. You can now download .capx through it.

Saturday, July 13, 2013 at 12:28:14 PM
1
Altheon 1,041 rep

Hi Vladoss! your tutorial was great and this is the best inventory implementention we've seen here, but i would like to know how to expand with 5 equipment slots, its the missing piece that i cant wrap my head around on how to do on your inventory.
Can you help me?

Monday, October 14, 2013 at 12:44:22 AM
1
ffman22 5,300 rep

the reload button dont work?

Thursday, April 03, 2014 at 8:22:27 PM
1
Waltan 7,875 rep
Hi Vladoss! your tutorial was great and this is the best inventory implementention we've seen here, but i would like to know how to expand with 5 equipment slots, its the missing piece that i cant wrap my head around on how to do on your inventory.
Can you help me?
quoted from ffman22]
the reload button dont work?
[/quote]

Works for me.

[quote=Altheon

Can you tell me what you want in details?
Sorry for the long aswer.

Friday, April 18, 2014 at 5:49:28 PM
1
RookieDev 6,368 rep

Vladoss, If i wanted to use this method to make my Hotbar it would work fine.
What i dont understand is could i be able to move slots wherever i want?

I have a backpack that the player will keep all of his ingame items and it will not always be visible to the player and i would love to know if i can create slots where they are needed and if so how would i do that?
Or am i limited to how the array is drawn?

Tuesday, May 27, 2014 at 10:11:59 AM

Leave a comment

Everyone is welcome to leave their thoughts! Register a new account or login.