Array-based inventory

5

Index

Attached Files

The following files have been attached to this tutorial:

.png
.capx

array-based-inventory.capx

Download now 83.25 KB

Stats

13,884 visits, 43,517 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 7 Jul, 2013. Last updated 19 Feb, 2019

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.

  • 0 Comments

Want to leave a comment? Login or Register an account!