How do i fix this? (resolved)

everything worked fine before i added in ‘setInterval’ to make it loop, after i included ‘setInterval’ the console said that i needed to define ‘isKeyDown’, how do i fix this?

var upspeed = 0
var downspeed = 0
var rightspeed = 0
var leftspeed = 0
function checkkeys() {
if (isKeyDown(“s”)) {
upspeed += 1.5
}
if (isKeyDown(“w”)) {
downspeed += 1.5
}
if (isKeyDown(“d”)) {
rightspeed += 1.5
}
if (isKeyDown(“a”)) {
leftspeed += 1.5
}
}
setInterval(checkkeys,500)
this.y += upspeed
this.y -= downspeed
this.x += rightspeed
this.x -= leftspeed

Can you send us a screenshot or gif of it going bonkers? I think that you might’ve messed something up somewhere but I won’t be able to know without some sort of proof that it doesn’t work

sure! here you go:


after i preview it, it keeps printing out this error message, is there any way to fix it?

also after a while it completely bricks the tab :(

The isKeyDown function is specific to the editor, so when used within the window through the setInterval function you get that error, or at least that’s how I would like to see it as.

Another thing I noticed from your console—

You got a lotta errors. Why? Well, your code is inside of the update script. The update script already loops all the code written inside of it, so when you try to loop the code inside of the update script that already loops the code, and the code your looping inside of a loop has an error… well, let’s just say numbers get big!

Judging from your code, I think it should work out fine if you replace the line

With just

checkkeys();

lemme know if this does it, or if you have any questions

question: does ‘update’ also reset every variable each tick?

The update script doesn’t reset every variable, but in your code, inside of your update script, you have

so every variable is being reset in the beginning of the loop.
If you want to set all variables to zeros only once in the beginning, then add a default script and set them there (default scripts run once in the beginning), and keep everything else in your update script the same.

it works now, how do i close the topic?

1 Like

Glad to hear that!

Only moderators can close topics. Adding something like “(resolved)” to the topic’s name is good enough to let others know that the issue has been resolved :+1: