|
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
|
07-12-2009 11:40
Does anyone know if there's an easy way to toggle between two scripts?
For example. I made a sentry drone that will follow my camera. I also made one that will wander around by itself.
If I wanted to put both of those scripts in the same drone, is there a way to tell it to shut down one script and fire up the other script on command, and switch back with the same command?
|
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
07-12-2009 11:49
you can use one script and have it change states instead
|
|
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
|
07-12-2009 11:54
I'm intrigued... How would that work?
|
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
07-12-2009 12:52
Try integer CHAN = 25; //Your channel goes here integer handle; default { state_entry() { handle = llListen(CHAN, "",llGetOwner(),""); } listen (integer channel, string object, key id, string message) { if (llToUpper(message) =="WANDER") { //Wander loosely on your own and do stuff } else if (llToUpper(message) == "CAMERA") { llListenRemove(handle); state camera; } }
state camera { state_entry() { handle = llListen(CHAN,"",llGetOwner(),""); } listen (integer channel, string object, key id, string message) { if(llToUpper(message) == "CAMERA") { //Follow the camera and do stuff } else if (llToUpper(message) == "WANDER") { llListenRemove(handle); state default; } }
or you could do everything in a single state and use your message ("CAMERA" or "WANDER"  to switch between functions. Beware: I make typos. This is a schematic script. 
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
|
Destiny Niles
Registered User
Join date: 23 Aug 2006
Posts: 949
|
07-12-2009 13:42
From: Paul Wardark Does anyone know if there's an easy way to toggle between two scripts?
For example. I made a sentry drone that will follow my camera. I also made one that will wander around by itself.
If I wanted to put both of those scripts in the same drone, is there a way to tell it to shut down one script and fire up the other script on command, and switch back with the same command? Using state is the better way, but as always, at least a dozen ways to do the same thing. You can also use LinkMessages to tell the other script to start/stop and or use SetScriptState to stop the scripts. You can either use put the LinkMessage or SetScriptState in the scripts themselves or use a controller script.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-12-2009 19:20
if the scripts use very similar code you don't even need 2 states, just some if/elses and a single integer switch if they have wildly different code I'd go with the different states, and if they have lots of wildly different cods you could use a controller script and the two separate scripts, setting them to running or not running via llSetScriptState (you may want use either lSO compiled scripts for that, or llResetOtherScript, as mono scripts that aren't running when they cross sim boundries or go to inventory get reset anyway... you can call reset of non-running scripts before setting them active again)
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|