alternative for 'For Each loop' using a map variable

the print i added should have worked if it was in the inventory but you’re right it might not be where i think it is. for context here’s the structure for the inventory item data:

enum for item data:

this is a bp class for the football

a bp class for another item (ice cream)

and this is a master item blueprint class, which combines any items bp classes (the two previous ones: ice cream and football) and organises them

this is partly why im so confused. i dont know what holds what or where my item is even stored during the gameplay because there’s just so. much. stuff.

It’s ok. It’s better to focus on making sure fragments work rather than the system as a whole.

IMO this is where our attention should be right now:


Place a breakpoint at the return node of the function. It should focus when the player receives the item. Let me know if that works.

yep it did.

Good.

At the top of the blueprint window yo have these icons:
image
Click the “Step to next node…” (right arrow icon) until you exit the function. Hopefully this should be close to where the item gets added to the inventory.

Share a screenshot of that BP please.

if i simulate and pause i cant see any step to next node icon

Did you add the breackpoint? Don’t see the red circle:
image
Should look like this when it breaks:
image

ohhh gotcha, i pressed the button with the arrow going right all the way and it went to here

Awesome!

Is this true or false when the player receives the football?

this is the whole function

since i dont have the football already, it is false, then adds it to the inventory

Ok so inside Add Item to Inventory the struct should break, setting the string as key and a copy of the struct as value. Can you share the bp for that?

this is the item data struct

and if i continue through the nodes it goes here

and then to the event graph of AC_Inventory

not sure where to find what you mentioned

Inside AC_Inventory component, double click this node:
image

lol my bad, okay i double clicked and now im here

Ok. This is the heart of the inventory. Everything is stored inside that map variable.

The inventory component also has some functions to check what it contains. This is the function you should use to check if something is in the inventory or not:
image
This functions should take a string or the struct as argument and should return either true or false. Its what should be used over the map variable a few posts back.

Makes sense?

ohh i get it now! okay this is the ‘is item already in inventory’ function bp

how should i implement what you mentioned? and then would i still be looking for ‘Football’ using find in the NPC bp?

Here. After the first branch you should:

  • Add a GetPlayerCharacter node.
  • Then GetComponentByClass
  • In the class argument select AC_Inventory.
  • From the GetComponentByClass, drag from the output and add IsValid node (should have ? icon). From here also drag and look for IsItemAlreadyInInventory node.

An inventory interface could be more convenient but lets just get it working. Also looking back part of the issue is that there is no reference to the inventory component of the character.

Yes.

ok this is what i have so far

i dont have a reference to ‘isItemInInventory’ and its not coming up either

Drag from here:


If it doesnt show then cast to AC Inventory and then search for it from the cast node.

ok got it, but now how do i connect find to all of this? do i attach ‘is item in inventory’ to find or do i attach it to the branch condition?