I'm making a game in Microsoft MakeCode Arcade for a school project, and I wanted to know if there was a "repeat [function] until [property = true]" type of loop like there is in Luau. I wanted to use this so that the game waits until my player sprite is at a certain coordinate to run some code. I figured out a way to do this in a different way, but I wanted to know just for future reference.
If anyone is wondering, this is what the alternative way I am using.
game.onUpdateInterval(100, function () {
if (level == 1) {
if (myPlayer.x == 950 && myPlayer.y == 140) {
myPlayer.y = 100
myPlayer.x = 10
if (game.ask("Does " + level_1 + " + " + level1_2 + " = " + level1CorrectAns + "?")) {
console.log("Level 1 Completed successfully")
level += 1
LevelChange()
} else {
game.over(false)
}
}
}
})
You could use either
while
loop ordo...while
loopFor
while
loop, the following code will keep on running as long as the condition is true.For
do...while
loop, the following code will keep on running as long as the condition is true. And this loop will run at least once.Coming back to your example, I believe you're running the loop every
100ms
(based on first argument of yourgame.onUpdateInterval
.You could easily do this by adding a
timer
function and wrap this loop in as an async function.While I'm not 100% sure of the functionality of your current workaround, but this is my interpretation (Hope it works)