Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

"Run time error", "Math Error"

LIO Diesel
Registered User
Join date: 2 Sep 2008
Posts: 28
12-18-2008 08:20
On adding this script to a sphere prim, some time it is showing "Run TIme Error" with "math error" code is below..
suggest something.


vector V;
default
{
state_entry()
{
//llSensorRepeat("","",AGENT,1,TWO_PI,1.0);
//llSetCameraEyeOffset(
}
collision(integer total_number)
{
vector inipos=llGetPos();

V=llDetectedVel(0);
float speed = llVecMag(V);
vector D = V / speed;

//lOwnerSay( ""+(string)D);
if(D.x>0 && D.y>0)
{llSetPos(llGetPos()+<2,2,0>;);
llSleep(2);
llSetPos(inipos);
jump end;}

if(D.x<0 && D.y<0)
{llSetPos(llGetPos()+<-1,-2,0>;);
llSleep(2);
llSetPos(inipos);
jump end;}

if(D.x>0 && D.y<0)
{llSetPos(llGetPos()+<2,-2,0>;);
llSleep(2);
llSetPos(inipos);jump end;}

if(D.x<0 && D.y>0)
{llSetPos(llGetPos()+<-2,2,0>;);
llSleep(2);
llSetPos(inipos);jump end;}

@end;
}
}
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
12-18-2008 08:24
Maybe speed is 0?

Does the problem happen on every collision?
Cappy Frantisek
Open Source is the Devil!
Join date: 27 Oct 2006
Posts: 400
12-18-2008 12:20
From: Sindy Tsure
Maybe speed is 0?

Does the problem happen on every collision?

That would do it and I would suspect that is the case as collisions are unreliable at best.
Ollj Oh
Registered User
Join date: 28 Aug 2007
Posts: 522
12-18-2008 18:34
vector D=ZERO_VECTOR;
if (speed)vector D = V / speed;

Youre asking the wrong question to understand your problem:
You ask "why does this script crash when it should keep running?"
You should ask "why does this script even work when it should not, ever"?
Because, let me get this right, on a colission event you divide by the speed and wonder about a math error?
The only way this event does NOT divide by zero is when the physic engine is not accurate or when the functions are just a little laggy!
In a Newtonian sim you will always divide by zero with your function.
Luckily SL has time dilation, lots of asynchronous lag and only measures distances very inaccurately, so you get lucky too often to divide trough a quantum-remainder.

Your error, that still happens in quantum-sl; You divide by zero because your quantum remander is only rounded to 31 bit and therefore will be 0 on still to mayn types of colisions no matter how laggy the region is. (speed=llVecMag(llDetectedVel(0) should return 0 on any colision. but it doesnt because its inaccurate and your float measures that inaccuracy enough to divide by a fraction of inaccurate colision inertia)
90% of math errors are dividing by zero and the other 11 % are squarerroots of -1%.

other solution for other targets:
"speed must be a global variable and speed must remember the last speed BEFORE the colision (wich means laggy timer)
or speed must be the speed AFTER the colision (colision_end).
LIO Diesel
Registered User
Join date: 2 Sep 2008
Posts: 28
12-18-2008 23:43
no, not always.......only some times ........
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
12-18-2008 23:50
sometimes.... when speed is 0 i would expect --> put in llOwnerSay("debug - " + (string)speed); just before the division you'll soon see it
_____________________
http://slurl.com/secondlife/Together
LIO Diesel
Registered User
Join date: 2 Sep 2008
Posts: 28
12-19-2008 01:44
Correct Escort, When speed is 0 i changed speed to 1. also replaced collision() to collision_start(). now it is not showing any error....
thanks for support.