alternative for 'For Each loop' using a map variable

hi everyone,

in my game i have an inventory variable of type map (following a tutorial, where part is string and the other is the inventory struct) and i want to find a specific item in my inventory.

however, a ‘For Each loop’ doesnt take map variables. Does anyone know of any alternatives to ‘For Each loop’ for a map variable or if i have to change my inventory type, how would i do that so i can have a string and struct in one variable? (i’d prefer not to do this since it’s hooked to a billion other things and i dont have time to go through each one)

a quick fix would be appreciated :slight_smile:

(ue5.2.1)

Get keys from the map, loop over that → find.

3 Likes

thank you! that worked. kinda still have an issue with this section overall if anyone can help (im a ue5 noob btw so bear that in mind)

im looking for an item ‘Football’ in my inventory, and if it is found, my npc says a certain dialogue. the top part of this bp works (followed a tut for it) , the second part doesnt work AT ALL. am i being dumb and doing something completely wrong pls lmk ive been stuck on this for days.

If by any chance Football is at the last index the branch and everything after will execute twice:
image

IMO this is what should go there:

Right click the first node after EventTalkAfterDialogue and add a breakpoint. Does it stop?

2 Likes

okay so i’ve actually tried to use find already, it also doesnt work. not sure what a breakpoint does (ik its some time of debug but when theres nothing happening theres nothing to debug … :frowning: ) but i added it anyway and nothing changes

also i added another talk index (i dont know if the original one stays as the final number it is on or goes back to 0 so i just made a new one)

i cant understand the issue, looks like the first person in the world trying to do a quest system like this…

i think the event is just not being called at all or something? i have no idea whats going on.

It’s not meant to change anthing. Does it stop execution and focuses the node with the breakpoint?

1 Like

also, i tried adding the whole bottom section on the end of the top one and i did get the first message in the ‘after item index’ appear but i didnt even have the item. so i think it’s partially an issue of the event not being called at all and something alone the line not working either.

idek how to make that event be called. everything ive done is by following tutorials, and theres no tutorial for any of this lol

Where is this supposed to be called?
image

1 Like

ok i understand the breakpoint now, and no it didnt focus. so i have a BPI called Dialogue with two functions. Talk and TalkAfterDialogue (this should be talk after item but anyway) so as far as i know it should be fine? maybe beginner mistake.


Here you are only calling Talk, not TalkAfterDialogue. That’s probably why it never executes:

Keep in mind that this is based on what you’ve shared. IMO it’s more likley to be the issue but we will know after this has been sorted and the breakpoint executes.

1 Like

i have two events on one event graph, i thought i am calling both? how do i fix that :frowning:

That depends on why there are two in the first place. Whats the purpose of the second one? Under what conditions was it designed to be called?

1 Like

so the first one is for dialogue the NPC is going to say when the player talks to them (“can you find my ball?”)

the second is supposed to be dialogue for when the player has the ball in their inventory and they talk to the NPC. to which the NPC would reply “thank you for finding my ball”.

the first one is being called and works perfectly with 0 issues. i still dont understand how to be able to call the second one.

Ok. So… what I recommend you do is make only 1 event that checks for the item. The only thing the event has to change is the FString value (the dialogue) depending if the item was found or not.

1 Like

i basically stuck them together now, butttt yeah still no change.

Where does the execution stop?

1 Like

so i added a breakpoint here (between the first part and the second) and as soon as i intereacted with the NPC it focused.

i then put one on ‘Add AC Inventory’ and it focused too. i added the branch and it focused too. however i never got the print string to focus or even print.

so, this means the issue now is that it cant find the football in my inventory. back to the beginning lol. this is one function in my AC_Inventory (theres a lot so here’s one that checks if an item is in the inventory) but yeah not sure what to do.

That’s good. Now you know where to look.

When the player receives the item, do you have any way of debugging that it is actually stored in the inventory?

1 Like

not a debugging way but i can see that item in my inventory when i play the game. im basically combining two tutorials from two different youtubers,

this is one big playlist of the inventory system

and this is the dialogue system tutorial

Ok. The point of the question is to see if you understand where it is and how it can be accessed. A simple button that checks and prints at the start of the game and right after the player receives the item will go a long way.