Using oncollides as functions really only applies to people like Kilinich, who frequently use phunlets and might need to have phunlet-friendly functions.
I don't really remember how exactly oncollide-functions work, but I think you call the functions with 'e.geom.oncollide" in a laser colliding with a geom containing a function in the oncollide. Currently, I'm buried underneath several tons of C and NXT-G, so my thyme might be a little rusty.
So I would recommend you stay away from functions stored in oncollides or onhitbylaser for now, and use console-based functions instead. You enter functions into the console similarly to the way you enter scene.my variables, except you must include any inputs that the function will use. So if you want a function that adds two numbers, the code will be:
- Code: Select all
Scene.my.addnum = (x, y) => {
Answer := x + y;
Answer;
};
Or you could go functionless and simply put that code into an oncollide or onhitbylaser. The benefit of functions is that you only have to write out a simply tag to reuse code rather than having to write out the entire block of text again.
The functions in the scene _should_ output true/false depending on whether or not the mouse is inside the shape. Since algodoo is coordinate-based, this will depend on how the shape described on a coord plane.
So, on a coord plane, a circle would be described as a locus of points that are all a given distance from a center point. To check if the mouse is within a circle, we could simply figure out whether the mouse is within a given distance of the center point. That is what the is ispointincircle function does.