How to find the index of a specific element

For example when you have an array of images you want for your sprite and you use it for a sprite’s image, is there a way to have an if statement checking which index is used, and if that index is used, make the sprite have different properties?

Its at the bottom of the Array category!

Block:

1 Like

stupid stupid stupid

I forgot to add the image block sorry

I don’t think the builtin blocks will work.

You would need to do it this way in JavaScript:

let index: number = -1
images2.find((value: Image, i: number) => {
    if (value.equals(needle)) {
        index = i
        return true
    }
    return false
})
game.splash(index)

@Sarge or @WoofWoof , I’ve forgotten: Does either of your extensions includes the find() function?

2 Likes

Looks like @Sarge’s does!


You can find it by putting this link in the extensions search bar!
https://github.com/sargedev/betterarrays

2 Likes

oh right, images are pointers kinda