Check elements of one Enum array against another Enum array

I am trying to make a door that will open when you have multiple unique keys and I want to use this door multiple times in different locations and levels. The list of keys are in an enum and so far I am able to assign which keys the door needs. The issue comes when trying to check if the player has the correct keys. If I use the “contains item” node then I can only check for one key at a time instead of multiple.

Is there a way to check the player key list against the door lock list to make sure the player has at least all the required keys without making a spaghettis monster? The image bellow is the code I’m using, but as you might guess it does not allow the player to hold extra keys.

The end goal is to make one door I can assign 1 or more unique locks to depending on which keys I want to put in the level.

Surely ‘contains item’ does it? The door only has one key, and the player has a list?

But for this you need to loop over the door locks and check the player has each.

A quick idea:

  • set the door enum variable to instance editable.
  • create an interface function that takes enum array as parameter.
  • override the function in the door and have it find the required key each time player interacts.
  • thats it… just instance the door.

I think the OP wants a way to neatly manage doors with multiple keys ( right? ) ( I realised, after thinking about it ).

1 Like

Have an array of enums in the door and the player.

When the player tries to use the door ( this is in the door BP )

1 Like

I’m still a bit new to scripting, but I’m trying to make a “boss door” that requires 5 unique keys hidden throughout the level to open, but the door is also used for smaller bosses that require 2 unique keys to open. If I use “contains item” then I can only check one at a time and I end up needing about 12 branches. Is this unavoidable or is there a node like “contains all” that I could use?

1 Like

See above :slight_smile:

You can just set the keys on the door when you place it. Or you can set them randomly etc.

What is the “return node” and “will open” are those just like notes to say where they go?

It’s a function

When you want to use it in the event graph

1 Like

Thank you so much, I didn’t know about that!

1 Like

Useful, eh? :slight_smile:

You can also turn it into a ‘pure’ function, here

Then, when you use it, it will look like this

You have to be careful with pure functions though, make sure you only have one wire coming off that pin, otherwise they will do strange things.

2 Likes

Nice work, only thing I’d adjust is to use an Interface and pass the keys. That casting loop is killing me inside.

1 Like

Right, of course. But this was enough to get across in one block.

If I’d put BPIs in there too, it would have not been useful.

The cast is only run for each key, it’s not really a sin. Technically, we should get the player array ref once, yes, but it’s not going to effect anything :smiley:

Personally I wouldn’t even bother with the ref, that’s the point of the BPI.

But yeah I get yah. To the point functionality.

Again, nice work.

1 Like