I wrote some javascript code in droidscript but it won't work. I made several attempts to fix it, even deleting irrelevant code, but it still won't print any thing to the console, what's wrong with it?
var Vector = function(x, y) {
this.x = typeof x == "number" ? x : 0;
this.y = typeof y == "number" ? y : 0;
console.log("vector created");
this.length = function() {
return Math.sqrt(x * x + y * y);
};
this.sub = function(vec) {
return new Vector(this.x - vec.x, this.y - vec.y);
};
};
function slope(pos1, pos2) {
console.log("slope calculated");
return (pos1.y - pos2.y) / (pos1.x - pos2.x);
}
function calc_vector(f, s) {
console.log("vector calculated");
return new Vector(f * Math.cos(s), f * Math.sin(s));
}
function normal_force(forcevec, s) {
var f = calc_vector(-forcevec.length(), slope(forcevec, new Vector()) - s);
console.log("normal force calculated: " + f.y);
return f.y;
}
//Called when application is started.
function OnStart() {
var force = normal_force(new Vector(0, 1), 45);
console.log(force);
}
OnStart();
console.log() is tolerated, but in DroidScript, it does not display anything. The following code overrides the console object and creates an appropriate layout context for your snippet. Chose to create a 'New JavaScript App', insert your code at the indicated location, and it will run straight away in DroidScript.