var sprite = createSprite(40,200);
sprite.setAnimation("greenAlien");
var spriteoriginalposx = sprite.x;
var spriteoriginalposy = sprite.y;
var timer = 80; //timer used to limit how long sprite walks across screen
function draw() { //my lazy way of making a loop
timer = (timer - 1); //timer count down
background("orange");
if (timer > 0){ //checking if timer has reached 0/ended
sprite.rotation = randomNumber(-10, 10);
if(sprite.x > 380){ //sets the sprite back to original spot when it reaches the end of screen
sprite.x = spriteoriginalposx; // ↑↑↑↑
} else { //if the sprite is not at the end of screen
sprite.x = (sprite.x + 10); // makes the sprite "walk" in increments of 10
sprite.rotation = 0;
for (let CurrentXpos = sprite.x; sprite.x === 200; CurrentXpos = sprite.x){ // loops until sprite is at the middle of the screen
sprite.x + 10; //moves the sprite until the for loop above ends ↑
}
}
}
drawSprites(); // creates each frame of the sprite movement
}
When I run this code in game lab I get the error
“ERROR: Line: 18: SyntaxError: Unexpected token (18:15)”
I’m quite clueless on what the cause of this is and I tried double checking my brackets and semicolons but I didn’t notice anything that would cause the code not to work, maybe someone here will see what’s wrong
I don’t think this matters very much, all I want is for the code to run, but it’s supposed to make the sprite walk across the screen a couple times, then walk to the middle, and stop.
Thanks for reading!