You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用MakeCode Arcade扩展开发游戏时遇e.findIdx is not a function错误

问题:MakeCode Arcade循环生成敌人时出现e.findIdx is not a function错误

我在VS Code中使用Microsoft MakeCode Arcade扩展开发游戏,尝试通过for循环自动生成敌人时遇到了错误。

错误信息

VS Code报错内容:

Uncaught e.findIdx is not a function
   at lvl1 (main.ts:105:1)
   at inline (main.ts:54:57)
   at runButtonEvents (pxt_modules/game/controllerbutton.ts:237:9)
   at inline (pxt_modules/game/controllerbutton.ts:266:45)
   at inline (pxt_modules/base/eventcontext.ts:32:59)

MakeCode Arcade网页端报错内容:

e.findIdx is not a function
  at lvl1 (line 118)
  at inline (line 57)
  at inline (line 6)

我猜测该错误可能与存储精灵变量的数组有关,但无法确定具体原因。

疑似问题代码段

let enemys: any = []
let enemyNumber: number
for (let i: number = 0; i < 3; i++) {
    // enemy setup
    enemyNumber = i
    enemys[enemyNumber] = sprites.create(assets.image`Basic Enemy`, SpriteKind.Enemy)
    enemys[enemyNumber].vx = -30

    // enemy movment setup
    game.onUpdateInterval(200, function () { // evry 0.2 sec          
        if (enemys[enemyNumber].vx == 30) {  // if the player is traveling right
            if (!(tiles.tileAtLocationIsWall(enemys[enemyNumber].tilemapLocation().getNeighboringLocation(CollisionDirection.Right).getNeighboringLocation(CollisionDirection.Bottom)))) { // if the tile to the below and to the right of the sprite is not a wall
                enemys[enemyNumber].vx = -30 // make the sprite turn the other direction
            }
        } else {
            if (!(tiles.tileAtLocationIsWall(enemys[enemyNumber].tilemapLocation().getNeighboringLocation(CollisionDirection.Left).getNeighboringLocation(CollisionDirection.Bottom)))) { // if the tile to the below and     to the right of the sprite is not a wall
                enemys[enemyNumber].vx = 30 // make the sprite turn the other direction
            }
        }
    })
}

tiles.placeOnTile(enemys[1], tiles.getTileLocation(10, 14))
tiles.placeOnTile(enemys[2], tiles.getTileLocation(20, 14))
tiles.placeOnTile(enemys[3], tiles.getTileLocation(29, 11))

已尝试的排查步骤

我注释掉了代码中的115-135行,但错误仍然存在。这可能意味着问题与预定义资源有关,但我完全无法理解该错误信息的含义,寻求帮助。

内容的提问来源于stack exchange,提问作者Comrade Bacon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 15:58:11