Issue with functions

Essentially, I’m trying to move my AI for some enemies into a function on the frame, so the enemy clones can just call back to that rather than have their own entire ai running, which has caused lag issues.

Though for some reason, I can’t get it to recognize any function.

When is just out the function as “run();”
It says that it isn’t defined when It is in default of the frame.

So I tried to put *project.run();" which does allow it to recognize it as a function, but it recognizes the whole thing as a function rather than just “run”, leading to it saying it’s undefined.

Not sure how to get it to call back to the function on default.

Screenshot 2026-01-08 12.30.12 PM Screenshot 2026-01-08 12.39.25 PM

hey @Leaf , can you post your .wick project file in this thread? I can take a peek and see what’s going on

Easy. The problem is that variables created in events (using var, const, let or function) are restrained to the event (for safety reasons). You can use this or project to define the function, either specifically for your Clip, or for the entire project.

project.magnitudeOfVec2 = function(x,y) {
  return Math.sqrt(x**2 + y**2);
}

this.magnitude = function() {
  return Math.sqrt(this.x**2 + this.y**2);
}

if(this.magnitude() > 50) this.remove();
if(project.magnitudeOfVec2(bullet.x, bullet.y) > 50) bullet.remove();