Inventory system, copy ID?

Get help using Construct 2

Post » Sun Feb 19, 2017 12:47 pm

Hello there! ^_^
So i have been learning and following this tutorial - https://www.scirra.com/tutorials/583/easy-inventory
It is indeed amazing. Only thing i changed was to add number if existing item is in inventory, so if i pick up same item it will take a whole new space. So, i have 2 questions;

1. I want the item i pick up to copy its ID such as strength/healing etc and add it to the array, how do i do that?
In the tutorial above i cant find 'space' to copy the ID from the item picked up to the item created in inventory?

2. I want a 36 slot inventory system, should i use 'Width' only and place them 6 and 6 underneath? Or is it better to use 'height' in some way to add the ones under? And how would that go?

Thanks in advance ^_^
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Sun Feb 19, 2017 1:23 pm

Hi, I am doing an inventory system myself currently, displayed as a grid (it works so far) and also did some stuff related to it in the past.

1) The example in the tutorial has a function for that "AddToInv". From what I understand you pass the ID of the item as parameter 0 when you call the function "AddToInv". Look into the capx of the tutorial for the function call action in event 6.

2) If you are using the exact same functions as the tutorial you can't just change to the height to 6 to have a 6 by 6 grid as the example uses row 1 on the Y axis to store the number of items of a given ID.

There are basically two approaches here, both are valid and possible to use, but I believe the first one is a lot easier to manage (and I used it myself):

A) Always use the X axis to store items and the Y elements for each X axis element as the items properties. So have an array of 36 width with whatever height you need (I do not know what information besides item name you need to store in the array).

Advantages:
- very easy to add remove new items from the array, as you can just pop and push, and use "array.width-1" to retrieve the index of the last added (empty) x element, and don't need to do custom functions for it.
- counting empty space or number of items is easy (equal to array.width).

Disadvantage:
- requires a bit of tinkering to have it display as an item grid. Basically you need to map a one dimensional X index to a row/column combination. Not hard, but it is some extra work. But not much as your inventory slots will need a row and column position anyway, regardless if you go with a 2D array or a 3D array.

B) Do a 3 dimensional array, with x and y being grid position and z-axis elements being item data. IMO this is a lot better for maps or other grid-based structures where you need to check relative position, calculate distance, angle or do any kind of shapes. Personally I use a 3D array for a tilemap.

Advantages:
- easier to map to a grid

Disadvantages:
- counting empty slots or finding an empty slot is more difficult.
- you can't just add a new item by pushing a new X level element easily. Well you can, but you are basically creating new slots at the same time. So to use the array effectively, you would need to have logic to find if you have empty slots, where there is an empty slot and if no empty slots are available to push a new array element.
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Sun Feb 19, 2017 1:31 pm

Pulstar wrote:Hi, I am doing an inventory system myself currently, displayed as a grid (it works so far) and also did some stuff related to it in the past.

1) The example in the tutorial has a function for that "AddToInv". From what I understand you pass the ID of the item as parameter 0 when you call the function "AddToInv". Look into the capx of the tutorial for the function call action in event 6.

2) If you are using the exact same functions as the tutorial you can't just change to the height to 6 to have a 6 by 6 grid as the example uses row 1 on the Y axis to store the number of items of a given ID.

There are basically two approaches here, both are valid and possible to use, but I believe the first one is a lot easier to manage (and I used it myself):

A) Always use the X axis to store items and the Y elements for each X axis element as the items properties. So have an array of 36 width with whatever height you need (I do not know what information besides item name you need to store in the array).

Advantages:
- very easy to add remove new items from the array, as you can just pop and push, and use "array.width-1" to retrieve the index of the last added (empty) x element, and don't need to do custom functions for it.
- counting empty space or number of items is easy (equal to array.width).

Disadvantage:
- requires a bit of tinkering to have it display as an item grid. Basically you need to map a one dimensional X index to a row/column combination. Not hard, but it is some extra work. But not much as your inventory slots will need a row and column position anyway, regardless if you go with a 2D array or a 3D array.

B) Do a 3 dimensional array, with x and y being grid position and z-axis elements being item data. IMO this is a lot better for maps or other grid-based structures where you need to check relative position, calculate distance, angle or do any kind of shapes. Personally I use a 3D array for a tilemap.

Advantages:
- easier to map to a grid

Disadvantages:
- counting empty slots or finding an empty slot is more difficult.
- you can't just add a new item by pushing a new X level element easily. Well you can, but you are basically creating new slots at the same time. So to use the array effectively, you would need to have logic to find if you have empty slots, where there is an empty slot and if no empty slots are available to push a new array element.


So how to copy a paremeter if it has more than 1 ID? i cant go X,X,X to copy 3 ID's to the new item
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Sun Feb 19, 2017 3:02 pm

Please clarify what exactly you want to do. Do you want to copy 3 new items or add an item with 3 properties?
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Sun Feb 19, 2017 3:33 pm

Pulstar wrote:Please clarify what exactly you want to do. Do you want to copy 3 new items or add an item with 3 properties?


* Item on ground has;
HpID:175
MpID:125
VitalityID:100

* - When the item goes from ground to inventory, we want the HP/MP/Vitality ID values to follow
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Sun Feb 19, 2017 4:27 pm

Anyone else knows?
B
12
S
3
Posts: 164
Reputation: 1,530

Post » Sun Feb 19, 2017 4:55 pm

Share a .Capx with ....

The graphics for the items and there instance variables filled with values.
The graphics & grid for the inventory.

I suppose that is gonna be 2 layouts ? 1 with the play field and 1 with the inventory system ? Or how do you planned to get items from the play field to the inventory ?

In short, lets split the work, and i will help you. With pleasure.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Feb 19, 2017 8:34 pm

Greaver wrote:
Pulstar wrote:Please clarify what exactly you want to do. Do you want to copy 3 new items or add an item with 3 properties?


* Item on ground has;
HpID:175
MpID:125
VitalityID:100

* - When the item goes from ground to inventory, we want the HP/MP/Vitality ID values to follow


The first thing you need to do is define how you store the HP/MP/Vitality data of the item, so from where is the data supposed to be copied. Let's assume the simplest case, that you have it as variables of an object (sprite) that represents the item. On Item pickup the object will be destroyed but only after you store the item in the inventory.

This is how it can be done (there are arguably better, but more complicated and requiring more explaining ways). For example:

When the player clicks or does some other action triggering item pickup, you call an "Item Pickup" function, and pass all the properties of the object as parameters of the function. So name, HpID etc. would all be instance variables of the item object (sprite).

So you would have a call function "item pickup" action with parameter 0 = item.name, parameter 1 = item.HpID, parameter 2 = item.MpID and parameter 3 = item.VitalityID.

Next you need to have the "item pickup" function store the data passed as parameters in the inventory array. I have no idea how many item statistics you exactly need, but you need at least 4. So your array, if it is a 2D array like in the inventory tutorial example, it needs a height of 4.

Now, the important thing you need to do, is to write down which row stores what information for an item. Let's assume for the purpose of this example the following, as it is consistent with what we used in the parameters:

y = 0 is the name of the item
y = 1 is HpID
y = 2 is MpID
y = 3 is VitalityID

Assuming you know into which element x (slot) you want to put the item into, which I shall simply call "i" (short for index) here, all you need to do is use the set array value at action as follows in the "on function "Item Pickup" event:

Set value at X=i Y=0 to function.param(0)
Set value at X=i Y=1 to function.param(1)
Set value at X=i Y=2 to function.param(2)
Set value at X=i Y=3 to function.param(3)

That's it, the data will be stored in the array. You just need to know at what element x to store it, pass the right values in the function and make sure the array has the correct height so that it can store y from 0 to 3.
B
15
S
6
Posts: 85
Reputation: 1,195


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 24 guests