Controls

Control the flow of your program: conditionals, loops, error handling, and sprite cloning.

wait
// Pause the script for a number of seconds
self.wait(1);
for
// Count from one number to another, running code each time
for (let i = 1; i <= 10; i++) {}
View on MDN ↗
while
// Repeat code while a condition is true
while (false) {}
View on MDN ↗
doWhile
// Run code once and then repeat while a condition is true
do {} while (false);
View on MDN ↗
break
// Exit the innermost loop immediately
break;
View on MDN ↗
continue
// Skip to the next iteration of the loop
continue;
View on MDN ↗
controls_if
// Run code only when a condition is true
if (false) {
}
View on MDN ↗
controls_if_else
// Run one block of code or another depending on a condition
if (false) {
} else {
}
View on MDN ↗
ternary
// Choose between two values depending on a condition
false ? null : null;
View on MDN ↗
tryCatch
// Try to run code and catch any error it throws
try {
} catch (error) {}
View on MDN ↗
throw
// Throw an error
throw "error";
View on MDN ↗
whenCloned
// Run code when this sprite is cloned
self.whenCloned(() => {});
clone
// Create a clone of a sprite
self.clone();
delete
// Delete this clone
self.delete();
stop
// Stop the whole project
Scrap.stop();
stopOtherScripts
// Stop the other scripts running on this sprite
self.stopOtherScripts();