https://arcade.makecode.com/S25068-43644-56620-20957
every time i try to remove the text with the remove HUD, it recognizes the array length is 3 but the loop only runs 2 times
press a and then b to recreate
https://arcade.makecode.com/S25068-43644-56620-20957
every time i try to remove the text with the remove HUD, it recognizes the array length is 3 but the loop only runs 2 times
press a and then b to recreate
Use debug mode and step through your code, and watch your arrays — particularly, their lengths.
For simplicity, I’ll use the JavaScript version of one of your loops:
for (let index = 0; index < arrayOfText.length; index++) {
sprites.destroy(arrayOfText[arrayOfText.length - 1])
arrayOfText.pop()
console.log(arrayOfText.length)
}
Each time through the loop, the conditional is evaluated. Since you’re using arrayOfText.length in the conditional, your conditional statement is changing each time you go through the loop.
You just want to destroy the sprites in the array and then clear the array, yes? Do those two steps separately: