Thursday, January 05, 2006

In which the Safety of Vehicle Passengers is Discussed

One thing I've always found annoying in SL is the number of times people fall out of vehicles. I've been on a few newbie tours with the SPSL, where we descend on a Welcome Area, grab a couple of newbies and whisk them off, and without fail at least one of them jumps out. (Perhaps that says something about our conversation.) Similarly, when I was attending a building session on Tuesday, held on a platform high above the ground, people seemed unable to stay seated.

One of the problems is that you often don't realise that whoever it is has fallen out until another passenger looks around and says "oops, we just lost X". In a vehicle, that means they're back somewhere on the ground, one of many possible green dots, and sometimes you can't find them at all. I therefore decided to create a script that would at least inform the occupants when this happened.

I shall be putting it in my showroom later on, as it now works, but it is based around the fact that when somebody sits on or gets off an object, the number of linked primitives in that object changes. The avatar is treated as a prim itself. This triggers an event which can be detected by a script.

Scripts can also obtain a list of the prims that make them up, as well as the names and keys of those prims. It is quite easy to find out the name of somebody who has just got on board, as they will simply be the last one on the current list. (The event actually tells you what their key is so if you were only concerned with people getting on board, you wouldn't need to bother with prim lists at all - you could just get their name straight from that.) If they've departed, though, clearly they're not on the list any more, so you have a slight problem.

The pseudocode for my script looks something like this:

On startup
Get a list of prims in the object (we assume that nobody is sitting on the object). This is the "base list". Any more prims will be treated as passengers.
Also save this as the "old list" to start with - see below.

When a prim is linked or delinked
Get the current list of prims in the object ("new list").
If linked (more prims than previously i.e. someone has gotten on):
* Say "hello" to the last name on the "new list".
If delinked (fewer prims than previously i.e. someone has gotten off):
* Go through all the names on the "old list" that aren't on the "base list".
* For each of these, check whether they are still on the "new list".
* If not, you've found who's gotten off. Say "goodbye" to them.
Either way, after you've finished, set the "old list" to the "new list".


In practice you don't actually need to save the "base list" since you don't care what's on it - all you need to do is save the size, and only check items on the old and new lists that have an index greater than that size. If there are 18 objects on the base list you know you only need to check objects 19+ to see who's left, because those are the only ones who will be passengers.

The effect of this is that the object you drop the script into whispers "Hello, X! I now have Y passengers" or "Goodbye, X! I now have Y passengers" on sitting or unsitting, which can be heard by everyone. One could also add any other functions that one wished to activate on boarding or disembarking, giving notecards, rezzing a platform underneath them etc. Because it also has the key of anyone who's left, I thought that a possible enhancement might be to then set up a sensor to find out where they'd actually got to - say whispering every few seconds "X is 25m north-east" or something - which would help you find them.

0 Comments:

Post a Comment

<< Home