How to iterate trough a list of spritekinds?

I need help iterating trough a list of spritekinds! What im trying to do is first iterate trough a spritekind, and then iterate trough all sprites that spritekind has.

let optimizeSpriteKind = [SpriteKind.Coin]

function IsInScreen(sprite: Sprite) {
    let ox = scene.cameraProperty(CameraProperty.X)
    let oy = scene.cameraProperty(CameraProperty.Y)

    if (sprite.x + sprite.width > ox - (xw / 2)) {
        if (sprite.x - sprite.width < ox + (xw / 2)) {
            if (sprite.y + sprite.height > oy - (yh / 2)) {
                if (sprite.y - sprite.height < oy + (yh / 2)) {
                    return true
    return false

forever(function () {
    for (let kind of optimizeSpriteKind) {
        let allSpritesKind = sprites.allOfKind(kind)
        for (let sprite of allSpritesKind) {
            if (sprite.isOutOfScreen(game.currentScene().camera)) {
                sprite.setFlag(SpriteFlag.Invisible, false) //testing
            } else {
                sprite.setFlag(SpriteFlag.Invisible, true) // testing

Once again i have no idea why this doesnt work

You can try this to iterate through a list of sprite kinds.

I know, but im going to iterate trough a list of spritekinds and then iterate trough a list of all sprites with that spritekind

I got what you mean, try this: add all the spritekinds to an empty array manually, and then, iterate through the array to pick the expected spritekind. Next, iterate through the sprites of the spritekind to pick the expected sprite.
I think it will definitely help you!

Thanks for the help, but i’ve already figured it out: the spritekinds initialize a bit later than when the array is made, so all the values in the array are undefined. I just added a “do after 500ms” code with the timer extension to fix this