Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Script randomly stops

Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
12-09-2006 16:14
My following script randomly stops working ("running" checkbox is unchecked), usually after about 1 hour. why is this?


CODE

string prey = "A-Life Fish";
float hunger = 0;
float idlespeed = 1; //Rate at which it moves when idle
integer ate;
integer spawn;
integer death;

breed()
{
llRezObject("Shark",llGetPos() + <0,0,.5>,<0,0,0>,<0,0,0,0>,0);
}

default
{
object_rez(key child)
{
llGiveInventory(child, llKey2Name(child));
}

state_entry()
{
llSetBuoyancy(1);
llSensorRepeat(prey,NULL_KEY,ACTIVE|PASSIVE|SCRIPTED,50,PI,1);
llSetTimerEvent(1);
}
timer()
{
hunger = hunger + 1;
llSetText("",<1,1,1>,1);
if (hunger >= 140)
{
death = death + 1;
hunger = 0;
//llDie();
}
}

sensor(integer num_detected)
{
vector detectpos = llDetectedPos(0);
if (hunger >=101)
{
llLookAt(llGetPos() + llGetVel(),1,1);
}
if (hunger <=100)
{
vector mypos = llGetPos();
vector myvel = llGetVel();
llLookAt(<mypos.x + myvel.x,mypos.y + myvel.y, mypos.z>,1,1);
}
vector movevec = detectpos - llGetPos();
if (hunger <=0)
{
hunger = 1;
}
float speed = (3.5 - 100/hunger);
if (speed <=0)
{
speed = 0;
}
movevec = llVecNorm(movevec)*(speed);
llApplyImpulse(movevec,FALSE);
}

no_sensor()
{
//llSetText("No Fish to Eat",<1,1,1>,1);

}

collision_start(integer num_detected) //incase the fish runs into something
{
string hit = llDetectedName(0);
if (hit =="food")
{
hunger = hunger - llRound(llFrand(10));
}
if (hunger <=0)
{
hunger = 0;
}

if (hit == "A-Life Fish")
{
ate = ate + 1;
hunger = hunger - (75 + llRound(llFrand(25)));
if (hunger <=0)
{
hunger = 0;
}

if ((hunger <=30))
{
spawn = spawn + 1;
hunger = hunger + 100;
//breed();
}
//llOwnerSay("Eating fish hunger is now " + (string) hunger);
}

}



}
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Lightwave Valkyrie
Registered User
Join date: 30 Jan 2004
Posts: 666
12-09-2006 17:21
i had a simular problem with some thing that ran on a track,
i think its physics when theres a problen it turns off the script.
i dont remember but i think i fixed this by auto resetting the script,
its gone now cause it just got too laggy when it was running
SL is just not good these days for much of anything...
-LW