Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Newbie Question: Multiple Scripts

Edgar Ellison
Registered User
Join date: 18 Sep 2006
Posts: 13
10-14-2006 11:54
How do multiple scripts work in the same object, if they may have conflicting tasks? For instance, if one script causes the object to turn red when touched, and another has it turn blue when touched, exactly what happens when you touch the object?

If one script has the object wander around -- moving in one direction and changing its direction at random intervals -- but another script tells the object to move towards the closest avatar it sees, exactly what happens when it's set loose?
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
10-14-2006 12:00
They race. In the case of the red and blue scripts, whichever does its action LAST wins. Think about it... one script turns the object red, and then the second turns it blue, and that's what it stays until the next time you touch it. When multiple scripts have conflicting actions, all of them are done. They're done in series, but it's usually so quick that you can't tell which order they're happening in unless you look at the end results.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
10-14-2006 12:13
From: Edgar Ellison
How do multiple scripts work in the same object, if they may have conflicting tasks? For instance, if one script causes the object to turn red when touched, and another has it turn blue when touched, exactly what happens when you touch the object?

If one script has the object wander around -- moving in one direction and changing its direction at random intervals -- but another script tells the object to move towards the closest avatar it sees, exactly what happens when it's set loose?



You give Strife a heart attack
Edgar Ellison
Registered User
Join date: 18 Sep 2006
Posts: 13
10-14-2006 21:09
From: Lex Neva
When multiple scripts have conflicting actions, all of them are done. They're done in series, but it's usually so quick that you can't tell which order they're happening in unless you look at the end results.


Okay. (I'm asking because I'm building stuff based on existing scripts.) Now, what do I do to get two scripts to run together in harmony?

Alluding to my previous example: My creature wanders around until it detects others of its type, then "swarms" towards them. In other words, the "wander" script normally runs over and over until the sensor in the second script, the "swarm" script, detects another creature. Maybe some other condition causes the second script to return control to the first.

How would I handle this? Thanks.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
10-15-2006 00:49
Link messages http://lslwiki.com/lslwiki/wakka.php?wakka=llMessageLinked will let scripts in a prim talk to each other, so you can have your sensor and swarm script send out a "I'm swarming type message" to turn the random wandering off, and when it can't find anyone turn it back on.

Alternatively of course you splice the two scripts together. You're using some variation on llSensorRepeat or llSensor + timer. Use the sensor() event to move at the target, no_sensor to move randomly.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog