# Weighted inventory?

0 favourites
• 9 posts
From the Asset Store
Template for maintaining an inventory with crafting possibilities. Completely documented in text and video.
• Im trying to create a weight limit to the inventory.

One way to do it I thought would be to add 2 global variables one is weight, the other is weight limit, weight limit can be levelled and the weight represents your current weight, which I want to manipulate by an array. I don't know how to make a condition to get value y for each spot in the array to be weight. Say I have wood in my inventory and each piece of wood is 5lbs. So y in the array is the amount of a particular item if thats 4 you will have added 20lbs to your weight. here is a concept I cant seem to figure out-

if array contains x(ID of the object)

addto Weight: InventoryArray(X, see condition) *(multiplied) corisponding y index?

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• You could have the item name in x,0, the amount in x,1 and the weight in x,2, and the combined weight in x,3. Drop in the for loop so it comes out as set value at loopindex,3 to loopindex,1*loopindex,2.

Now all the total weight you're carrying is in y=4 for every item. You would now just total everything in y=4 as the total weight and compare it to the allowed weight limit.

Made an example here: https://www.dropbox.com/s/dm0rs5ryi8rtb ... .capx?dl=0

• Quite late! I took a break from coding for a bit. In concept it sounds great but I'm not sure how to implement it into my existing code.

• Well I made an example capx there, if you can't slot those events in share your own capx and I can take a look.

• https://www.dropbox.com/s/6ujs1cjnoiia5 ... .capx?dl=0

The inventory array is arr_inventory

• I've dropped it into the Update Inventory function as that seems the best place. At the moment it just adds y=1, which is the amount of each individual item, to the inventory (so everything has a weight of 1). As mentioned above if different items have different weights then you can put a calculation in and set up a total weight for each item type in another y column and run through that instead of y=1.

https://www.dropbox.com/s/ksskijrn2w8iu ... .capx?dl=0

• Another y column?

• You've added the amount to y=1 in the array in the pick up logic, you could add the weight of an item to y=2, then do y=1*y=2 into y=3 to get the total weight taken up by one item.

• It already counts weight for as many items as I pick up, Im not sure how to choose the item itself. Would I use 'x has value' as a second condition?

• 9 posts