Link_Message, if else, TRUE/FALSE
|
|
Leon Castro
Registered User
Join date: 27 Sep 2006
Posts: 9
|
10-07-2007 07:02
I want a set of linked prims to appear as others disapear and some not change. I got it working by having if else in the child prim, setting it to alpha and back again. But this set up seemed to be easy to get out of sync so..........here is my attempt to put if else in the root prim to send different messages to the children. It compiles ok but does nothing, I can touch it only once and then touch is not possible. Any advice would be greatly appreciated. 2 Scripts Following. ***Root Prim Script*** [script] integer y = FALSE; default { touch_start(integer total_number) { if ( y == FALSE ) { state holster; } else if ( y == TRUE ) { state inhand; } } } state holster { state_entry() { llMessageLinked(LINK_ALL_CHILDREN , 99, "INHOLSTER", NULL_KEY); y = TRUE; } } state inhand { state_entry() { llMessageLinked(LINK_ALL_CHILDREN , 99, "INHAND", NULL_KEY); y = FALSE; } } [script] ------------------------------------------------------------------------------------ ***Child Prim Script*** [script] default { link_message(integer sender_num, integer num, string str, key id) { if ( str == "INHOLSTER" ) { llSetAlpha( 1.0, ALL_SIDES ); llSay(0, "see me"  ; } else if ( str == "INHAND" ) { llSetAlpha( 0.0, ALL_SIDES ); llSay(0, "Dont see me"  ; }}} [script]
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
10-07-2007 07:40
You are stuck in state inhand. To fix it either go with: integer y = FALSE;
default { touch_start(integer total_number) { if ( y == FALSE ) { state holster; } else if ( y == TRUE ) { state inhand; } } }
state holster { state_entry() { llMessageLinked(LINK_ALL_CHILDREN , 99, "INHOLSTER", NULL_KEY); y = TRUE; } } state inhand { state_entry() { llMessageLinked(LINK_ALL_CHILDREN , 99, "INHAND", NULL_KEY); y = FALSE; state holster; } }
Or even better, there is no need to switch states: integer holster = TRUE;
default { touch_start(integer total_number) { if ( holster == TRUE) { llMessageLinked(LINK_ALL_CHILDREN , 99, "INHOLSTER", NULL_KEY); holster = FALSE; } else { llMessageLinked(LINK_ALL_CHILDREN , 99, "INHAND", NULL_KEY); holster = TRUE; } } }
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Leon Castro
Registered User
Join date: 27 Sep 2006
Posts: 9
|
10-07-2007 08:07
Thankyou Jesse but it still doesnt work, I can touch it many times now so looks like that is fixed. Maybe the script for the child is not working? I can trouble shoot the child script with more confidece now.
|
|
Ace Cassidy
Resident Bohemian
Join date: 5 Apr 2004
Posts: 1,228
|
10-07-2007 08:17
You need 'touch_start' event handlers in ALL of your states, not just the 'default' state. Once you switch states, there are no handlers for the touch events.
- Ace
_____________________
"Free your mind, and your ass will follow" - George Clinton
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
10-07-2007 08:21
You are making progress then! This main script and child script does work for me though when I tried it in a link set. When you try it are you getting the "see me", "Don't see me" messages? If not then have you double checked to see if the gun and the holster are actually linked? TO debug it just create 2 simple prim, put the scripts in and link them then touch it. It will turn the child prim visible/invisible and give the says.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Leon Castro
Registered User
Join date: 27 Sep 2006
Posts: 9
|
10-07-2007 08:28
I am just testing with two prims, but after you said it worked for you I pasted my child script and your root prim script into new prims and it worked. Maybe my prims were all worn out. Thankyou very much for all your help
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
10-07-2007 08:33
From: Ace Cassidy You need 'touch_start' event handlers in ALL of your states, not just the 'default' state. Once you switch states, there are no handlers for the touch events.
- Ace heehee, yep I didn't even try his script out and instead pointed out that there was no call to change the state and went with integer tests instead. To use the state change script, it would need to be changed to this:
default { touch_start(integer total_number) { llMessageLinked(LINK_ALL_CHILDREN , 99, "INHOLSTER", NULL_KEY); state inhand; } } state inhand { touch_start(integer total_number) { llMessageLinked(LINK_ALL_CHILDREN , 99, "INHAND", NULL_KEY); state default; } }
As you can see there is no need to declare the integer because it is never used anyway. But in a case like this it is more efficient to use an integer test instead of doing a state change and easier on the sim. You can actually see the extra work taht has to be done if you create a project in LSLEditor and look at the Debug: They both give the same output: Object2: see me Object2: Dont see me Object2: see me Object2: Dont see me But using state changes makes this sim do this: *** state_entry() *** touch_start(1) MessageLinked(-3,99,INHOLSTER,00000000-0000-0000-0000-000000000000) state->inhand *** state_exit() *** state_entry() *** touch_start(1) MessageLinked(-3,99,INHAND,00000000-0000-0000-0000-000000000000) state->default *** state_exit() *** state_entry() *** touch_start(1) MessageLinked(-3,99,INHOLSTER,00000000-0000-0000-0000-000000000000) state->inhand *** state_exit() *** state_entry() *** touch_start(1) MessageLinked(-3,99,INHAND,00000000-0000-0000-0000-000000000000) state->default *** state_exit() *** state_entry() While using an integer test it only has to do this: *** touch_start(1) MessageLinked(-3,99,INHOLSTER,00000000-0000-0000-0000-000000000000) *** touch_start(1) MessageLinked(-3,99,INHAND,00000000-0000-0000-0000-000000000000) *** touch_start(1) MessageLinked(-3,99,INHOLSTER,00000000-0000-0000-0000-000000000000) *** touch_start(1) MessageLinked(-3,99,INHAND,00000000-0000-0000-0000-000000000000) *** touch_start(1) MessageLinked(-3,99,INHOLSTER,00000000-0000-0000-0000-000000000000) See the difference?
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Leon Castro
Registered User
Join date: 27 Sep 2006
Posts: 9
|
10-08-2007 00:53
I have been working on making the script talk to a prim set that is not linked and again I get no result, any help is greatly appreciated. --------------------------------------------------------------------------------- //root prim in holster sends linked_message to all children and msg on channel 59 to gun in hand. integer holster = TRUE; default { touch_start(integer total_number) { if(llDetectedKey(0) == llGetOwner()); { if ( holster == TRUE) { llMessageLinked(LINK_ALL_CHILDREN , 99, "INHOLSTER", NULL_KEY); llSay(59, "in hand"  ; holster = FALSE; } else { llMessageLinked(LINK_ALL_CHILDREN , 99, "INHAND", NULL_KEY); llSay(59, "in holster"  ; holster = TRUE; }}}} --------------------------------------------------------------------------- //root prim in gun recives msg on channel 59 from root prim of holster and passes linked msg to all prims in gun. string sCommand = "in holster"; string hCommand = "in hand"; integer chan = 59; integer holster = TRUE; default { state_entry() { llListen(chan,"",llGetOwner(),"string msg"  ; } listen(integer channel, string name, key id, string msg) { if (msg == sCommand) { llMessageLinked(LINK_SET , 99, "INHOLSTER", NULL_KEY); holster = FALSE; } if (msg == hCommand) { llMessageLinked(LINK_SET , 99, "INHAND", NULL_KEY); holster = TRUE; } } }
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
10-08-2007 03:49
llListen(chan,"",llGetOwner(),"string msg"  ; should be: llListen(chan,"",llGetOwner(),""  ;
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
|
10-08-2007 05:52
From: Leon Castro I have been working on making the script talk to a prim set that is not linked and again I get no result, any help is greatly appreciated. --------------------------------------------------------------------------------- //root prim in holster sends linked_message to all children and msg on channel 59 to gun in hand.
From: someone llListen(chan,"",llGetOwner(),"string msg"  ; As Jesse said, drop the string msg from inside the ""'s. Also with the key set to llGetOwner() the script will only listen to the owner, not any of the owner's objects. So your first script won't be able to communicate with the second. instead your listen will look like this: llListen(chan,"object name","",""  ; replacing object name with that of the holster (any change to the holsters name will break this script though). Also, you can test if the message came from a holster owned by the gun owner (so your not crossing wires with another gun/holster owner) using: if (llGetOwnerKey(id) == llGetOwner()) after the line listen(... and using curly brackets to contain the whole of the listen event as shown below: listen(integer channel, string name, key id, string msg) { >if (llGetOwnerKey(id) == llGetOwner()) >{ >>if (msg == sCommand) >>{ >>>llMessageLinked(LINK_SET , 99, "INHOLSTER", NULL_KEY); >>>holster = FALSE; >>} >>if (msg == hCommand) >>{ >>>llMessageLinked(LINK_SET , 99, "INHAND", NULL_KEY); >>>holster = TRUE; >>} >} } note that the > are used to show the indents (and therefore the bracket architecture) and should be removed.
_____________________
www.nandnerd.info http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
10-08-2007 06:20
From: nand Nerd As Jesse said, drop the string msg from inside the ""'s. Also with the key set to llGetOwner() the script will only listen to the owner, not any of the owner's objects. So your first script won't be able to communicate with the second. instead your listen will look like this: llListen(chan,"object name","",""  ; replacing object name with that of the holster (any change to the holsters name will break this script though). heehee That was what the other problem was. I was trying to debug and get ready for work at the same time this morning.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
|
10-08-2007 07:17
From: Jesse Barnett heehee That was what the other problem was. I was trying to debug and get ready for work at the same time this morning. Now that is dedication! Hope there are sufficient grateful souls out there to warrant your attention. 
_____________________
www.nandnerd.info http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
10-08-2007 14:36
OK I'm back! Here is what I was thinking today. Doing it like this saves on some of the sim resources: Touch the gun in the holster and it disappears and the one in the hand shows. Touch again and they switch. No use in using the link messages and having another script. Use llSetLinkAlpha instead. Don't make the simulator get the owners key every time it is touched, instead declare it a global variable and get the key in state_entry. If you want to give this to someone else or sale it then put an on_attach, on_rez, or changed owners test in here and llResetScript(). //Gun in holster
key owner; integer holster = TRUE;
default { state_entry() { owner = llGetOwner(); } touch_start(integer total_number) { if(llDetectedKey(0) == owner) { if ( holster == TRUE) { llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES); llSay(59, "hide"); holster = FALSE; } else { llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES); llSay(59, "show"); holster = TRUE; } } } }
//Gun in hand
integer chan = 59;
default { state_entry() { llListen(chan,"","",""); } listen(integer channel, string name, key id, string msg) { if (msg == "show") { llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES); } if (msg == "hide") { llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES); } } }
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
10-08-2007 14:43
I will make one more suggestion. You are coming along in your scripting and it is probably time to start using an outside editor. Scite-EZ or Notepad++ are both excellent but take a little bit more work to setup. I have been using Scite-EZ with lslint for quite a while now. But this set of scripts is absolutely perfect for running in LSLeditor and you can also test them. Download it and start a new project. Create 2 objects and put a script in each one. Paste these 2 scripts into those two scripts. Hit F5 and then touch while you are in the "holster in gun" script. You can actually see what each script is doing.
Makes it much easier to debug and you can hit F6 for it to check mistakes. If you click F1 when you are over a function then it will bring up the wiki entry for it. Hit ctrl D and it will auto indent your scripts etc. THe error checking isn't as strong as lslint yet but it is easy enough to use this and then paste and check in the lslint website if you have a problem you can't figure out.
Hang in there and keep on learning Leon!!!
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Leon Castro
Registered User
Join date: 27 Sep 2006
Posts: 9
|
10-09-2007 01:49
Thankyou for all your help, I am understanding more every day but can take 2 hours to learn one little thing, I do cut and paste most script from other people but am starting to be able to write sections on my own now.
|