I know “array of sprite kind”, but how can I do “array of all sprites”?
Easy to do in JavaScript, but tough to do in blocks.
In JavaScript:
function getAllSprites() {
const allSprites: Sprite[] = [];
for (const key of Object.keys(game.currentScene().spritesByKind)) {
for (const sprite of game.currentScene().spritesByKind[parseInt(key)].sprites()) {
allSprites.push(sprite);
}
}
return allSprites;
}
Thanks! I’ll stick to JavaScript.
We need a block for this
Good idea. That list will also include the player. Still you could check within the array if the sprite.kind is that of the player and skip doing something.
Property 'Push' does not exist on type 'number'
Why does this happens. I just copied and pasted in, but still will not work…
Can you share your project?
I really just pasted it, I don’t know how that happened, It happens on anything though, not just that project.
EDIT: it only happens in the offline app…
@richard
I came up with this… put the arrays in an array… well this happens…(read the error thing)
Also I realised that sometimes all pictures go blank… (bug) I think when you have an error and press on the error sign! I will do an experiment about it and tell you!
@DahbixLP that code is actually creating an array of arrays of sprites. In other words, it’s an array where each of the items is another array.
Noice
Wiat don’t it will break your project for some reason…