So i have a setup that lets you open an inventory and stacks items. All of the items follow the same structure. I’m trying to make it so i can pick up multiple stacks of ammo and if i run out of one stack, it still takes ammo from another stack efficiently. I was thinking about creating a separate blueprint for each ammo type, that way i can set up separate variables for the stacks, however i still am wondering how i can make it so if one runs out the remainder of needed ammo will come out of the other stack.
You’d want function that returns if there’s more ammo available of that sort, and which inventory index that can be found at (so you know where to subtract ammo from)
Such a function is a regular ForEachLoop iterating over the inventory until it finds a slot with the appropriate ammo type.
Hello @Squize !
Lol, i am a beginner with for each loops If you don’t mind me asking, where would i set up the for each loop? in my inventory widget? My item blueprint? or maybe my player blueprint?
Personally I’d have it wherever my inventory is stored / handled.
This is my current inventory blueprint now. With the update equipment slot function here as well. Would I be asking too much for you to walk me through this process? For each loops confuse me. I happened to know how to make arrays with them, but an iterating function is new to me
This is probably the solution i need. I just need to understand it better. I will try to implement this and see how it turns out. Thank you for the speedy responses
Ok, I’ve done some studying and I think ive figured this out.
So it would make a separate array out of the ammo type. Now my thing is if i have multiple stacks of ammo, how do i take from one after another if a stack isn’t enough to fill the mag? I feel like it would only take from that one stack it finds then I’d have to reload again intead of taking one after the other.
Well its kinda in your sentence. You need in the next check (the one that actually picks out ammo from the returned filtered array) how much ammo you can refill, and if the single next stack is enough for that. If its not, you wanna take everything in that stack, remove it, and recursively take more ammo untill there’s no more ammo to take, or the current clip is full