Choice of event based on index

Hi All,

I have a situation in my game, but not sure how to achieve it. Can someone please help me by giving some idea. I put a screenshot of my blueprint.

My requirement is I created an array of sequences, that will happen based on the same input key. For example, I press the β€œV” key in the keyboard to unlock the window, then pressing the same key to open the window, then pressing the same key to close window, and so on. This will be like more than 10 sequences in a row. I cannot put branch node for each of them.

What I did is I put boolean for each of these sequences to check if the sequence is completed or not. And created an array with the collection of all the booleans. Each time when I press the β€œv” key, it will check from the index 0 to the index of the last sequence (using the retriggable delay and branch nodes). If an index is true, it will check the next index, and so on. When an index results false, I want an Event to be played.

This is where I got stuck. For each index, there is a separate event has to be played. So, I create a variable for the index that resulted in false. But I do not know how to run an event based on this resulted index.

Can anyone please give me which node will do what I am trying to achieve.

Many Many Thanks in advance and I really appreciate your help.

Regards,

Sure you can! It’s not that hard. If this is the simplest way to do it, then do it! I think that would be cleanest, clearest, and least hacky.

Another option is to make each action be its own function, and then build an array-of-delegate, and bind each function to a slot in the array, and then invoke the delegates per array. I think you might need to actually indirect each of THOSE through a separate object, though, as delegates themselves can’t be in arrays (at least not in blueprints.) This would be Data Driven β„’ and therefore AAA β„’.

You could also do this by chaining Gate objects, although wiring everything up to close the gate behind them is probably more wiring than dispatching the things in a big select.

Or you could, the horror, use C++, where an array-of-function-pointers is NBD and you can just index and call.

2 Likes

Have you thought about doing chained states on the window?

On input get state of the window (enum) β†’ switch β†’ action β†’ update window state.

Each action β†’ update is a function or event.

Hi Thanks for the quickly reply. Yes, I would like to use the Enum. But there are lot of Enums available. I am not sure which one to choose.

HI, Thanks for your help. I guess this would help me. Let me give it a try.

Thanks again.

1 Like

Hi, I tried this method. It seems the events are not running from the Select node. Can you please check if you are able to see with Print string connected to each event.

Hi, Thank You. I will try this.

Thank You so much. It just works exactly as I wanted!!! :relieved:

It is 1 AM in here. So, now I will have a peaceful sleep. Thanks a lot !

FYI, you can have the same exact approach using an Var(Int), or Array(Int/string), or TMap.

Also, you may want to look into adding key spam prevention if the intent is to use player input execution.

1 Like

You need to make the time on a timer be greater than zero for it to actually start. That’s not done in the illustration for how to pick an event.

Thanks for the added information. I will keep them in mind.

Hi, Could it be a problem? Because I set it at 0, and it worked fine or me.

If it works for you, then great!