Check if an array contains a value

How do I…

Check if an array contains a value

What is the expected result

I have an array called “slime_positions”
And I want to add the values of “random_position_slime” only if there are no equal values in the “slime_positions” array

What is the actual result

Try to do it with js but error occurs

Related screenshots


You’ll need to iterate through each entry in the array and check the x & y positions are the same.

A simpler method, if you only need to check it exists, is to make slime_positions a structure, and only store the X & Y with a separator as a key. Then you only need to check the child exists, using the X & Y with separator.

Something like the following, where the separator is a semicolon (“;”):

1 Like