"while (this.hits(that))" doesn't work

currently, my code is similar to this:

function PlceHolder (thang){
while (this.hits(that)){
//whats in here doesn’t matter

it keeps telling me that “this.hits is not a function”

any fixes?

The function your defining is using the function keyword. When you define a function with the function keyword this gets changed to match whatever called the function, like the window object.

What you probably want to use is the arrow function that looks like this,

var myFunc = (param1,param2) => {
    // do something

The arrow function keeps the this keyword to the scope that declared it.

i changed it to var but now i don’t know how to call it

So this could be put into something like this,

var PlceHolder = (thang) => {
    while (this.hits(that)){
        //whats in here doesn’t matter

Then it can be called with PlaceHolder(thatThang); in the same clip/script. Or if it is to be used outside the clip/script then declare it with this instead of var.

I tried that but it keeps saying that it’s “not a function”

Can you send the .wick file?

no, i cant

Then can you send the code that’s not working

I’ve not tried, but while-loops in JS are tricky.
They will pull all resources as long as the loop is running, potentially crashing the browser.
I would move this code to the “update”-event, and simply check with if/else if the hit is still occuring. Thus wick has “it hands free” to do all the other stuff that needs top happen, for instance< moving the target for hit to register false at some point in the future…

1 Like

the hits function only updates every frame and the while loops updates many times in a frame so you need to create a function that basically does the same thing as the hits function