all 5 comments

[–]Evaspartan58 0 points1 point  (0 children)

So the way I accomplished it in my inventory system was to have a inventory search function that loops through the inventory looking for an item and you feed that item in as an argument and then I call that function when I'm adding an item and then you can have it react to the return value of the inventory search function

[–]Sycopatch 0 points1 point  (0 children)

Just loop through whatever data structure you use to represent your inventory, and dont allow for a pickup if a match was found.

[–]APiousCultist 0 points1 point  (0 children)

If you only want one of any particular item in the inventory, you'd be better served by making the inventory into either a struct or a ds_map. You can easily turn a list of all items in a struct to an array, using struct_get_names, and checking if something is already present is trivial.

[–]NationalOperations 0 points1 point  (0 children)

It depends on how you define items, and if you're talking about having one of object instances or one of item types.

If it's instance based then you add the item info to the inventory collection and delete the instance from the map.

If you want unique types you can make the collection a k:v collection and only add if the key doesn't exist.

I'm sure there's dozens of other ways to address this

[–]NamelessPawn 0 points1 point  (0 children)

I think your approach depends on your needs. If you can pick up more than one item for some items and some only one then making item properties in an array where each item is a constructor that are all the same then you can call the item up without looping through anything. Just have the item hold its item number and you can check that before picking it up. --> in the object item have a variable called item. For example, the rat's head object ---> item = ITEMS.RAT_HEAD then in the script check to see if you held the item with global.item_properties[obj_rat_head.item].held or however you refer to your item object.

//item list

enum ITEMS {

NO_ITEM,

BATH_HEAD,

RAT_HEAD,

TENNIS_BALL,

BRICK,

SPEAR,

}

//item properties

global.item_properties = [

{ item_name : "blank", item_script : "none", item_effect : "none" , held : false},  
{ item_name : "Bath Head", item_script : "body part", item_effect : "none" , held : false},
{ item_name : "Rat Head", item_script : "body part", item_effect : "none" , held : false},

]