making a script "listen" for another script?

Creating scripts
Post Reply
User avatar
Ozwell Wayfarer
Posts: 584
Joined: Thu Jan 10, 2013 10:32 am
Has thanked: 860 times
Been thanked: 972 times

making a script "listen" for another script?

Post by Ozwell Wayfarer »

I am working on something for the April hunt and my limited scripting knowledge has left me predictably stumped. I wonder if anyone can possibly help me.

Ok, so without giving too much away what I want to do it for some activity (could be a sound, particle effect, message, movement, whatever) to be triggered by the activation of another script.

So for instance, I want to set off a particle effect when someone opens a door.

I have my door script. ok. I have my particle script. cool..........what do I do to make the particle effect "hear" the activation of the door?

Thanks!

EDIT - additionally, it would be great if someone could help me figure out how to insert a distance limitation to the door. So it can only be activated when close by. I have this bit of code:

Code: Select all

if (  llVecDist(  llDetectedPos(i), llGetPos()  ) < 10 ) {
but I have no idea how to make it relate to my door script.
User avatar
Dundridge Dreadlow
Posts: 616
Joined: Mon May 06, 2013 2:23 pm
Location: England
Has thanked: 590 times
Been thanked: 339 times

Re: making a script "listen" for another script?

Post by Dundridge Dreadlow »

your particle script should have something like..

Code: Select all

// awesome particle script
flashyParticles()
{
// do something awesome particle-y here
}
default
{
   state_entry()
   {
       // change 4444 to somethign else if you like, long as it matches..
       llListen(4444,"", "", "DoorOpened");
   }
   listen(integer channel, string name, key id, string message)
   {
        if (message=="DoorOpened")
              flashyParticles()
   }
}
your door script should have something like...

Code: Select all

// moderately less awesome door script


// doesn't have to be touch, it should really be at the end of the door opening ??
touch_start(integer count)
{
    if (  llVecDist(  llDetectedPos(0), llGetPos()  ) < 10 )      // 10m distance from the door of the first clicker, if there are more than one, meh, who cares.
    {
          llSay(4444, "DoorOpened");
          // actually open the door, the rest of your script should presumably be in here
    }
}
etc :D

hope that puts you on the right lines. This is untested typed straight into the forum code :)
ImageImageImageImageImageImage
PS. Kitely is awesome.
User avatar
Dundridge Dreadlow
Posts: 616
Joined: Mon May 06, 2013 2:23 pm
Location: England
Has thanked: 590 times
Been thanked: 339 times

Re: making a script "listen" for another script?

Post by Dundridge Dreadlow »

or... in one script...

Code: Select all

// awesome particle script
flashyParticles()
{
// do something awesome particle-y here
}
default
{
  touch_start(integer count)
  {
    if (  llVecDist(  llDetectedPos(0), llGetPos()  ) < 10 )      // 10m distance from the door of the first clicker, if there are more than one, meh, who cares.
    {
          flashyParticles();
          // actually open the door, the rest of your script should presumably be in here
    }
  }
}
untested, typed into forum :)
ImageImageImageImageImageImage
PS. Kitely is awesome.
User avatar
Handy Low
Posts: 231
Joined: Fri Nov 08, 2013 3:38 pm
Location: Yorkshire, England
Has thanked: 207 times
Been thanked: 140 times
Contact:

Re: making a script "listen" for another script?

Post by Handy Low »

Just from the point of view of efficiency:

Code: Select all

        if (message=="DoorOpened")
That test will cause 10 comparisons at system level every time it's successful, one for each character in the string. If your listen channel is unique (and I recommend using something really obscure like -9328349781 rather than 4444, just in case), better to use something like "O" for opened and "C" for closed.

Individually, and on a quiet sim, little things like this probably make no detectable difference to performance. But collectively, and on a busy sim, they can indeed be noticeable.
Handy Low
Post Reply