Jump to content

Different reactions to different collisons


Hottie Something
 Share

You are about to reply to a thread that has been inactive for 4775 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I am trying to create a race finish line that detects and announce the winner and then the second place person.  Sorry I amm just learning this stuff.  I sort of have an idea what is wrong but I dont know how to fix it.  this is what I have right now.  Obviously its just detecting the first person across the line.

 collision_start(integer total_number)
    {
        string winner1 = llDetectedName(0);
        llSay(0, "We Have a winner! Congratulations " + winner1);
 
        string winner2 = llDetectedName(0);    
        llSay(0, "Second Place: " + winner2);        
        state off;
    } 

 

If soeone could tell me how to fix this and explain it a little to me I would be very grateful **Only uploaded images may be used in postings**://secondlife.i.lithium.com/i/smilies/16x16_smiley-very-happy.gif" border="0" alt=":smileyvery-happy:" title="Smiley Very Happy" />

Link to comment
Share on other sites

llDetectedName(0) is the FIRST person/thing that collided with the object.

So string winner1 = llDetectedName(0); is fine

but string winner2 = llDetectedName(0); is just going to use exactly the same, first/index0, name.

Use string winner2 =  llDetectedName(1); instead, which is the second/index1 collider

=============================

I'm assuming that's your immediate problem - you said "If soeone could tell me how to fix this" but didn't actually say what was wrong.  We'll be here should you need more help, we all started the same.

Link to comment
Share on other sites

Hm, I'd guess it doesn't actually have to happen that they both are in the same event call?

So you'd need some global variable for first winner atleast

then if that variable is already set and the second-place person collides the script knows theres already a winner and knows this is the second-place perosn

Link to comment
Share on other sites

Woot I got it working with some global variables and two different states

Globals
key winner1;
key winner2;
string winner1_name;
string winner2_name;

//

state 1....

winner1 = llDetectedKey(0);
        winner1_name = llKey2Name(winner1);
        llSay(0, "We Have a winner! Congratulations " + winner1_name);
        state second;

states 2....

winner2 = llDetectedKey(0);
        winner2_name = llKey2Name(winner2);    
        llSay(0, "Second Place: " + winner2_name);        
        state off;

 

Now I get the first person to collide as the winner and the second person to collide as second place...tyvm everyone for your input.  :D

Link to comment
Share on other sites

Your solution will work if the two contestants in 1st and 2nd place cause 2 events (which is by far the most likely case) - it won't however work, if the 2 are caught by the same event.

To make sure you cover both cases, you can use a list to store the two relevant contestants - the first one in position 0 and the 2nd one in pos 2. As the collision occurs, you check if the number of objects in the cillision is bigger than 1 - if it is, you have you're two contestants, if it's just one, you store it in your list and wait for the next collision to get the 2nd.

Link to comment
Share on other sites

Hi Darkie thank you for pointing that out.  I am a total beginner so could you give me some example code for such a thing? I did already rin into the issue that the first place winner if stopping right on the finish line could cause a second collision and get the title of second place as well so I added and if(winner2 != winner1).  But while I was testing it there was at least one time where it was a close race and one person got the winner and the second person had to go back across the finish line to get their second place title.  So maybe what you are sayig is the reason. 

Link to comment
Share on other sites

Here is a simple example of what I wrote about earlier:

 

list glStandings;default{	collision_start(integer num_detected) {		integer i = 0;		for (; i < num_detected; ++i) {			glStandings += llDetectedName(i);			if(llGetListLength(glStandings) > 1) {				llOwnerSay("The winner is " + llList2String(glStandings, 0));				llOwnerSay("The second best is " + llList2String(glStandings, 1));				glStandings = [];				return;			}		}	}}

 

 

I hope I didn't make any typos.

Your problem could be connected to the collision event - which one are you using? In theory, it should all be fine with the collision_start event. You could - to make it save - check in the same manner as you did if the person is in the event already - here is the example

 

list glStandings;default{	collision_start(integer num_detected) {		integer i = 0;		for (; i < num_detected; ++i) {			if(llListFindList(glStandings, [llDetectedName(i)]) == -1) {					glStandings += llDetectedName(i);				if(llGetListLength(glStandings) > 1) {					llOwnerSay("The winner is " + llList2String(glStandings, 0));					llOwnerSay("The second best is " + llList2String(glStandings, 1));					glStandings = [];					return;				}			}		}	}}

 

 

Link to comment
Share on other sites

At risk of confusing matters, how about something like this?  I'm not completely sure what would happen in the event of a dead heat, with two avatars hitting the finishing line at the same split second, but neither am I sure how much of an issue, in practice, that's going to be.

I could well be wrong there, though.

I'm adding people to the list "winners," though I'm not doing anything with it, in case we need a record of the placings later.

 

integer counter;integer n;list winners;list placings =[	"second","third","fourth"//and so on		];default{	state_entry()	{		//llSay(0, "Hello, Avatar!");	}	collision_start(integer total_number)	{		winners += [llDetectedName(0)];		counter++;		if(counter ==1){			llSay(0,"And the winner is "+llDetectedName(0));		}		else if (counter >1){			n = (counter -2);			if(n<3){				llSay(0,"And in "+llList2String(placings,n)+" place is "+llDetectedName(0));			}		}	}}

 

 

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4775 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...