Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Collision event not being calculated properly

Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
12-06-2005 21:39
in a nutshell, it is performing the if loop no matter what the prim collides into instead of only if it runs into teh specified name.

the hunger variable is a global variable defined and modified in several other places throughout the script, but it is "working as intended" for this part.

CODE

collision_start(integer num_detected)
{
string hit = llDetectedName(0);
if (hit == "A-Life Fish")
{
llOwnerSay("I hit a " +llDetectedName(0)); //Debugging code. this if loop is processed even if the prim collides with something labeled "Object"
hunger = hunger - llFrand(50);
llSetText((string) hunger,<1,1,1>,1);
if (hunger <=0)
{
hunger = 0;
}

}


}

_____________________
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.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
12-07-2005 03:45
No obvious error in the logic that I can see, although I'm caffeine deprived...

First thought, it's queuing to enter the collision event because it's doing other things. At the point it enters it has object name correct, but by the time it's processed the next command it's hit something else so the detected name has changed. I don't know quite how that works, but it might be what's going on.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
12-07-2005 06:44
nothing wrong with it though i would write it a bit differently.

CODE

collision_start(integer num_detected)
{
string hit = llDetectedName(0);
if (hit == "A-Life Fish")
{
llOwnerSay("I hit a " + hit); //Debugging code. this if loop is processed even if the prim collides with something labeled "Object"
hunger -= llFrand(50);
if (hunger <=0)
hunger = 0;
llSetText((string) hunger,<1,1,1>,1);
}
}


if you wanted to make it a bit more unreadable...
CODE

collision_start(integer num_detected)
{
string hit;
do
{
if ((hit = llDetectedName(--num_detected)) == "A-Life Fish")
{
llOwnerSay("I hit a " + hit); //Debugging code. this if loop is processed even if the prim collides with something labeled "Object"
if (0 > (hunger -= llFrand(50)))
hunger = 0;
llSetText((string) hunger,<1,1,1>,1);
}
}while(num_detected);
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
12-07-2005 09:05
I think I must have hit a bug with the actual prim that this script was in, because I copied and pasted the script into a new prim and everything is working out fine. I still can't figure out why it was behaving oddly in the 1st place.
_____________________
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.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
12-07-2005 11:02
Every now and again prims go rogue and these sorts of things happen. Perfectly good scripts stop working or work 'wrong'.

Of course it's not a bug, because it's so hard to replicate, but we've all seen it happen.

The make a new prim and put the script into it works most of the time.
Maria Loudon
Dark Kat
Join date: 26 Nov 2005
Posts: 16
12-07-2005 11:25
llDetectedName(0); is going to give you the wrong name. To get the name of the object that you colloided with you must call. llDetectedName(num_detected)); So this should work

CODE

collision_start(integer num_detected)
{
string hit = llDetectedName(num_detected);
if (hit == "A-Life Fish")
{
llOwnerSay("I hit a " +llDetectedName(num_detected)); //Debugging code. this if loop is processed even if the prim collides with something labeled "Object"
hunger = hunger - llFrand(50);
llSetText((string) hunger,<1,1,1>,1);
if (hunger <=0)
{
hunger = 0;
}

}


}
Maria Loudon
Dark Kat
Join date: 26 Nov 2005
Posts: 16
12-07-2005 11:27
llDetectedName(0); is going to give you the wrong name. To get the name of the object that you colloided with you must call. llDetectedName(num_detected)); So this should work

CODE

collision_start(integer num_detected)
{
string hit = llDetectedName(num_detected);
if (hit == "A-Life Fish")
{
llOwnerSay("I hit a " +llDetectedName(num_detected)); //Debugging code. this if loop is processed even if the prim collides with something labeled "Object"
hunger = hunger - llFrand(50);
llSetText((string) hunger,<1,1,1>,1);
if (hunger <=0)
{
hunger = 0;
}

}


}



lsl wiki is your friend
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
12-07-2005 11:45
CODE
 
collision_start(integer num_detected)
{
string hit = llDetectedName(num_detected);
}

hit will always be a null string, indexs used by the detected functions start at 0 and end at (num_detected - 1)

Any indication that llDetectedName(num_detected) will work is missinformed.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Archanox Underthorn
Registered User
Join date: 20 May 2003
Posts: 168
12-07-2005 11:48
uhmm, num_detected is set to the number of objects the scripted object is colliding with at the moment, doing llDetectedName(num_detected) actually wont work I don't think because say you were colliding with 1 object, it would run llDetectedName(1), when it should be running llDetectedName(0) (it starts its list at index 0)
_____________________
Archatek

Home to some of the highest quality katanas and other blades available in SL. Co-creator of the Samurai Island Combat System, one of the best melee combat systems available, come check it out!

___________________
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
12-07-2005 12:36
It might be worthwhile having it run a loop when it triggers, as a debugging aid:

CODE

integer i;
for(i = 0; i < num_detected; i++)
llOwnerSay("DEBUG: object "+((string)i)+" is "+llDetectedName(i));
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
12-07-2005 12:55
Thought:

If you are only interested in collisions from other fish, why not use the collision filter?
llCollisionFilter
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
12-07-2005 14:35
From: Strife Onizuka
Thought:

If you are only interested in collisions from other fish, why not use the collision filter?
llCollisionFilter


there's fish, there's food, there's predators, and there's avatars that I'm having behaviour being modified for, but only the part that was looking for the fish collision was not working.
_____________________
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.