Listen ONLY to Owner
|
|
Haplo Voss
Registered User
Join date: 18 Nov 2006
Posts: 137
|
03-05-2008 08:42
Ok, I give up. Here is a simple piece of code that listens for a command to turn lights on - on channel 1042: I cannot get it to listen ONLY to the owner. Anyone can walk up and from the chat line activate it. default { state_entry() { llListen(1042,"",llGetOwner(),""  ; } listen(integer channel, string name, key id, string message) { if(message == "On"  { //ON llSetPrimitiveParams ([PRIM_POINT_LIGHT, TRUE, <1, 1, 1>, 50.0, 50.0, 0.01] ); llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, TRUE]); } else { if(message == "Off"  ; //OFF llSetPrimitiveParams ([PRIM_POINT_LIGHT, FALSE, <1, 1, 1>, 0.0, 0.0, 0.75] ); llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, FALSE]); } } } So, where Have I gone wrong? I have tried every iteration of owner comparrison I know of and have found in these forums on both the llListen statement, and the qualifier at the beginning of the listen block. I can say /1042 On and activate it, but I am building a new HUD, where I use dialog menus and have the same qualifiers there that I've tried and still no success. I need this so someone can control their flying machine I've made without anyone else being able to. I even tried using the avatarID that sits on the flight controls as a qualifier and no good. Any ideas? Thanks - Hap EDIT: Basically, the main issue is if more than one person is within chat range of eachother... they can control each-others object!! So it's just a real mess.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
03-05-2008 08:50
llListen( 1042, "", llGetOwner(), "" ); looks fine to me....
just beware that it needs to restart the listen in it changes owners, since it'll be stuck with the last one (state_entry only being called when the state is entered) or move it to on_rez
_____________________
| | . "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... | - 
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
03-05-2008 08:53
Anybody can use it?? That's weird.. Nothing jumps out as being wrong with that code. This isn't a MONO sim, is it?
You might want to use an on_rez or changed event to reset the script when the object is rezzed or changes owner. Also, if you're going to be talking to this script via a HUD, I'm not sure that only listening to the owner will work - maybe somebody else knows but I think you'll get a different key if the HUD talks..
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
|
Zaplok Riggles
Registered User
Join date: 25 Feb 2008
Posts: 119
|
03-05-2008 08:53
From: Haplo Voss Ok, I give up. Here is a simple piece of code that listens for a command to turn lights on - on channel 1042: I cannot get it to listen ONLY to the owner. Anyone can walk up and from the chat line activate it. default { state_entry() { llListen(1042,"",llGetOwner(),""  ; } listen(integer channel, string name, key id, string message) { if(message == "On"  { //ON llSetPrimitiveParams ([PRIM_POINT_LIGHT, TRUE, <1, 1, 1>, 50.0, 50.0, 0.01] ); llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, TRUE]); } else { if(message == "Off"  ; //OFF llSetPrimitiveParams ([PRIM_POINT_LIGHT, FALSE, <1, 1, 1>, 0.0, 0.0, 0.75] ); llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, FALSE]); } } } So, where Have I gone wrong? I have tried every iteration of owner comparrison I know of and have found in these forums on both the llListen statement, and the qualifier at the beginning of the listen block. I can say /1042 On and activate it, but I am building a new HUD, where I use dialog menus and have the same qualifiers there that I've tried and still no success. I need this so someone can control their flying machine I've made without anyone else being able to. I even tried using the avatarID that sits on the flight controls as a qualifier and no good. Any ideas? Thanks - Hap EDIT: Basically, the main issue is if more than one person is within chat range of eachother... they can control each-others object!! So it's just a real mess. Not sure if this is the problem but I had a similar thing happen when I was making changes to my script. Originally, I had no qualification on the listen. Then, I added it as you did. It acted like the original listen was still running. So, in effect, I had the original prior iteration listen script (with no qualifiers) and the new qualified listen both setup. This would cause the script to listen on the same channel 1 as unqualified and 1 as owner only. I solved it by adding a state change to my script. When changing states, it kills all listens. This killed my "phantom" listener. Also, it's good practice to store the listen_handle and in state_entry do a llistenremove on it just to be on the safe side (it's what I always do now).
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
03-05-2008 09:10
meade brings up a good point, if the hud is ultimately issuing the commands, you'll need to make the listen open, and then test for the owners key IN the event using if (llGetOwnerKey( id ) == llGetOwner()) or something similar.... in that way it'll only listen to the owner, or objects owned by them. you could even prevent the owner from directly chatting to it by further filtering it with if (llGetAgentSize( id )) return; //-- if it's an av, ignore it.
_____________________
| | . "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... | - 
|
|
Haplo Voss
Registered User
Join date: 18 Nov 2006
Posts: 137
|
03-05-2008 09:13
Ok great, I will try adding a listen variable and changin it to state listening() or something to that effect.
Thanks tons, will report on results. - Hap
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
03-05-2008 09:23
From: Zaplok Riggles ...Originally, I had no qualification on the listen. Then, I added it as you did. It acted like the original listen was still running. So, in effect, I had the original prior iteration listen script (with no qualifiers) and the new qualified listen both setup. This would cause the script to listen on the same channel 1 as unqualified and 1 as owner only.. If you have a reproducable test case for this - if you can write down the steps needed to make this problem happen - it's worthy of a new SVC bug in JIRA. Depending on how often it happens, listens not getting cleaned up could be a nasty sim performance issue. (/me kinda doubts it's happening everywhere, all the time tho)
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
|
Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
|
03-05-2008 09:57
You should check some syntax mistakes though... else { if(message == "Off"  ; // ** //OFF llSetPrimitiveParams ([PRIM_POINT_LIGHT, FALSE, <1, 1, 1>, 0.0, 0.0, 0.75] ); llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, FALSE]); } ** you ended that line with a semicolon ";". Anyway because it is in an "else {" it will be executed... strange way to code. One more thing is that state_entry is triggered when you enter to the state, reset or save the script. So if you rezzed the object and nothing happened...it's ok. I'd recommend you to try this: default { state_entry() { llListen(1042,"",llGetOwner(),""  ; } on_rez(integer parameter) { llListen(1042,"",llGetOwner(),""  ; } listen(integer channel, string name, key id, string message) { if(message == "On"  { //ON llSetPrimitiveParams ([PRIM_POINT_LIGHT, TRUE, <1, 1, 1>, 50.0, 50.0, 0.01] ); llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, TRUE]); } else if(message == "Off"  { llSetPrimitiveParams ([PRIM_POINT_LIGHT, FALSE, <1, 1, 1>, 0.0, 0.0, 0.75] ); llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, FALSE]); } } }
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
03-05-2008 10:06
From: Kahiro Watanabe if(message == "Off"  ; Oooo.. Nice catch! From: Kahiro Watanabe default { state_entry() { llListen(1042,"",llGetOwner(),""  ; } on_rez(integer parameter) { llListen(1042,"",llGetOwner(),""  ; } Not sure that's what you want to do.. It would end up listening to both the original owner and everybody who's owned it since. If the object changed owners enough times, it would eventually fault with a Too Many Listens error. I like a nice easy... changed (integer mask) { if (mask & CHANGED_OWNER) llResetScript(); }
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
|
Haplo Voss
Registered User
Join date: 18 Nov 2006
Posts: 137
|
03-05-2008 10:24
Yep, thanks for catching the typo. No luck yet. I'm trying everything I can in the HUD and in the target object's script also.
I'm going to try creating a new HUD and scrubbing it in case there's a leftover somewhere... something just isn't right.
|
|
Haplo Voss
Registered User
Join date: 18 Nov 2006
Posts: 137
|
03-05-2008 11:04
Ok, I've lost my mind. Here is a sample of the HUD script and what it's doing... on_rez(integer rez) { llResetScript(); } touch_start(integer number) { if (llDetectedKey(0) == llGetOwner()) { channel = 1042; //Jerry is listening llSetTimerEvent(dialog_timeout); listener = llListen(channel, "", "", ""  ; llDialog(llDetectedKey(0), dialog_msg, dialog_buttons, channel); } } listen(integer channel, string name, key id, string msg) { if (llGetOwnerKey(id) == llGetOwner()) { if (msg == "Here's Jerry"  { llRezObject("Jerry", llGetPos() + <1, 1, 2>, ZERO_VECTOR, ZERO_ROTATION, 42); llPlaySound("greetings2",10); llSay(0,"Greetings. Please right click on me and choose 'Fly'"  ; } else if (msg == "More >>"  { llDialog(llGetOwner(), dialog_msg_more, dialog_buttons_more, channel); } else if (msg == "<< Back"  { llDialog(llGetOwner(), dialog_msg, dialog_buttons, channel); } else if (msg == "Fly Away!"  {llPlaySound("goodbye",10);llShout(1047,"Fly Away!"  ;} else if (msg == "Light"  {llPlaySound("lights",10);llShout(1042, "On"  ;} else if (msg == "Light Off"  {llShout(1042,"Off"  ;} else if (msg == "Start"  {llPlaySound("flightparams",10);llShout(1042,"Start"  ;} ... etc. etc. } else {llOwnerSay("You are not the Owner!"  ;} timer() { llSetTimerEvent(0.); llListenRemove(listener); llOwnerSay("Menu timing out."  ; } Main sample of flight receiver... on_rez(integer rez) { llResetScript();
} state_entry() { pilot = llGetOwner(); pilot_name = llKey2Name(pilot); llSetTimerEvent(60); llSetSitText("Fly"); llSitTarget(SIT_POS, ZERO_ROTATION); llSetCameraEyeOffset(CAM_OFFSET); llSetCameraAtOffset(CAM_ANG); llCollisionSound("",0.0);
... lots of flight engine definitions, etc. go here... } listen(integer channel, string name, key id, string message) { if (llGetOwnerKey(id) == pilot) { if (message == "Stop") { llMessageLinked(LINK_THIS, 1, "show", "" ); brake = TRUE; llWhisper(0,"We are stopped, " + pilot_name + ". You may choose START to resume flight."); llSetStatus(STATUS_PHYSICS, FALSE);
} else if (message == "Start") { brake = FALSE; llWhisper(0,"I hear and obey, " + pilot_name + ". We now begin flight."); llSetStatus(STATUS_PHYSICS, TRUE); } ...etc...
So, Does anyone have any ideas here? I'm sure I'm missing something stupid, but I can't seem to figure it. I'm even using my wifes account to give her av new copies every time I try, making sure she is the new owner, leaving the scripts open mod, and resetting them just in case.
Still no joy. Thanks everyone again, - Hap
If you would actually like to see *all* of the code, just let me know and I will post it, I just hate making things longer than necessary. Plus I don't think I will lose too much money if it all gets out... I still have the flyer I made ;)
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
03-05-2008 11:22
Again, nothing jumps out at me as being wrong. Then again, I missed the "if ();" earlier.. Something I always end up doing in any script that's taken more than a minute to write, is to add llOwnerSays at the top of each event to display what's happening and what info is being passed (like do "llOwnerSay ("listen heard " + message)" at the top of your listens). Also, I tend to make very sure that there's an ending "else llOwnerSay ("bogus!"  " or something at the end of if chains.. Maybe you could add some more debugging and let us know what it says?
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
|
Haplo Voss
Registered User
Join date: 18 Nov 2006
Posts: 137
|
03-05-2008 12:33
Ok, not sure whay, but I am having limited success with the following. Now I'm trying to figure out the state structure for the large / main script... integer listener = 0; integer channel = 1042; default { state_entry() { llOwnerSay((string)llGetOwner()); llListenRemove(listener); state listening; } } state listening { state_entry() { listener = llListen(channel,"","",""  ; } listen(integer channel, string name, key id, string message) { if (llGetOwnerKey(id) == llGetOwner()) { if(message == "On"  { //ON llSetPrimitiveParams ([PRIM_POINT_LIGHT, TRUE, <1, 1, 1>, 50.0, 50.0, 0.01] ); llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, TRUE]); } else if(message == "Off"  { //OFF llSetPrimitiveParams ([PRIM_POINT_LIGHT, FALSE, <1, 1, 1>, 0.0, 0.0, 0.75] ); llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, FALSE]); } llListenRemove(listener); state default; } } } Not sure about the fundamental difference on the location of the Listen event, but it would appear I am running into the same issue that Zaplok Riggles was running into from the looks of things. There is really nothing different in the logic of this code other than I called the listen from a state, rather than just including it in the main block. Will report on further happenings, and thanks again everyone. - Hap
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
03-05-2008 12:43
edit: and, if you didn't know it already, hit the forums Quote button to see the scripting indentation... Changing state will cause all listeners to be cleaned up for you - you don't really need to remember the handle and clean it up yourself if you're going to change state afterwards. listen(integer channel, string name, key id, string message) { if (llGetOwnerKey(id) == llGetOwner()) { if(message == "On") { //ON llSetPrimitiveParams ([PRIM_POINT_LIGHT, TRUE, <1, 1, 1>, 50.0, 50.0, 0.01] ); llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, TRUE]); } else if(message == "Off") { //OFF llSetPrimitiveParams ([PRIM_POINT_LIGHT, FALSE, <1, 1, 1>, 0.0, 0.0, 0.75] ); llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, FALSE]); } llListenRemove(listener); state default; } } It's just my personal preference but until I got the listen stuff sorted, I'd do something like this... listen(integer channel, string name, key id, string message) { llOwnerSay ("listen: heard '" + message + "' from " + name);
if (llGetOwnerKey(id) == llGetOwner()) { if(message == "On") { //ON llSetPrimitiveParams ([PRIM_POINT_LIGHT, TRUE, <1, 1, 1>, 50.0, 50.0, 0.01] ); llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, TRUE]); } else if(message == "Off") { //OFF llSetPrimitiveParams ([PRIM_POINT_LIGHT, FALSE, <1, 1, 1>, 0.0, 0.0, 0.75] ); llSetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES, FALSE]); } else { llOwnerSay ("listen: invalid command! '" + message + "'"); }
llListenRemove(listener); state default; } else { llOwnerSay ("listen: heard '" + message + "' from non-owner named " + name); } }
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
03-05-2008 13:14
Also, even with the semi-colon fix, the following (indentation purposefully set to show the actual construct, so hit quote to view): if (message == "On") { ... } else { if (message == "Off") doSomething(); doSomethingElse(); }
is very different from: if (message == "On") { ... } else if(message == "Off") { doSomething(); doSomethingElse(); }
Which seems like what you actually wanted. I suggest ALWAYS using curly braces for your control structures. It is good programming practice, and vastly increases readability.
|
|
Haplo Voss
Registered User
Join date: 18 Nov 2006
Posts: 137
|
03-05-2008 13:25
From: Hewee Zetkin Also, even with the semi-colon fix, the following (indentation purposefully set to show the actual construct, so hit quote to view): if (message == "On") { ... } else { if (message == "Off") doSomething(); doSomethingElse(); } is very different from: if (message == "On") { ... } else if(message == "Off") { doSomething(); doSomethingElse(); } Which seems like what you actually wanted. I suggest ALWAYS using curly braces for your control structures. It is good programming practice, and vastly increases readability. Indeed, I usually have cleaner code than I posted (such as the last one I posted) but it was an old light switch script I'd made long ago that worked... then wasn't careful enough to look it over better after setting it up. However, one thing I am curios on.. even if I use the "quote" button, I haven't seen the work in a LONG time, also quoting someone doesn't seem to show me any different than the plain window. Still trying to work out the logic on the main script, may have to break it up for my little head to grasp it. lol Oh, and I will use the php tags again from here on out, just the standard view nor the quoting does anything for me.. will look at my settings in the forums. Thanks, Hap
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
03-05-2008 13:59
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
|
Haplo Voss
Registered User
Join date: 18 Nov 2006
Posts: 137
|
03-05-2008 15:21
Yeah I know, and it's been a royal pain ever since.. thanks for the jira link, I just posted my 2 cents about it  Everything but the main script is working now... I haven't used state changes enough to track where I'm losing the logic at, so it will take me a while to reconstruct the script. Thanks again all and in return I will go ahead and post the finished code when it's properly done. It's a pretty fun HUD / flying machine type of setup that pretty much anyone could adapt to any menu-based flying object. My best, - Haplo
|
|
Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
|
03-05-2008 15:43
From: Haplo Voss Ok, I've lost my mind. Here is a sample of the HUD script and what it's doing... on_rez(integer rez) { llResetScript(); }
Wait wait wait, did you say "HUD"?. Well neither state_entry or on_rez will work with this, because hud goes attached so you have to use the attach() event to start the listener So: attach(key avatar) { if (avatar) // if it is attached { // you can start listener here, reset script or whatever } } -----------
|
|
Haplo Voss
Registered User
Join date: 18 Nov 2006
Posts: 137
|
03-05-2008 16:31
Ok, thanks... great piece of advice... I'm going to try it right now. I wondered if perhaps a worn item might be the problem. Hopefully I'm nearing the end of the tunnel here... lol
I hate to have to generate a random number for the listener, and then have to broadcast it every time the thing rezzes, because the HUD is what rezes the flying machine (amongst other menu functions of course.)
Thanks, - Hap
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
03-05-2008 20:18
The 'on_rez' event is triggered when an object is attached from inventory, just before the 'attach' event. I don't believe it is triggered when the object is attached from in-world. So that event may still work. Also, if you need a channel with which to communicate to a rezzed object, it might be a case where you CAN generate a random channel for each rez, and communicate it through the rez start parameter.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
03-05-2008 21:10
quoting to see indentation only works if you aren't in the advanced edit modes (set in user CP) if you are in one of the 2 basic modes it will show indents (and in the very basic mode, you'll see things like url and img tags instead of preformated tags)... strife's bbcode emulator for firefox also helps to see things like php formatting (so you don't have to quote to see it) links and instructions are in my signature
_____________________
| | . "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... | - 
|
|
Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
|
03-06-2008 03:15
From: Hewee Zetkin The 'on_rez' event is triggered when an object is attached from inventory, just before the 'attach' event. I don't believe it is triggered when the object is attached from in-world. So that event may still work. Also, if you need a channel with which to communicate to a rezzed object, it might be a case where you CAN generate a random channel for each rez, and communicate it through the rez start parameter. that's ture, I just tested it, an on_rez is triggered when agent attaches too. Anyway is a good practice to use attach(key id) because if id != NULL_KEY you know for sure that it is beeing attached.
|
|
Haplo Voss
Registered User
Join date: 18 Nov 2006
Posts: 137
|
03-06-2008 20:19
Well, I have finally gotten it to work, piece by painstaking piece.. LOL I think at this point I would have been better off having all of the remote objects scripts listen on a separate channel for the "new channel" when rezzed, then just remove that listener once it's been received. There are.... 5 different scripts in 5 different prims (including the one in the root) of a linked physical object that this HUD communicates with on various channels. I should be finishing up here using owner qualifiers, and If I can do that, it will be much more stable and dependable in my opinion. Thanks all, whenever it's completed I'll post what I have and anyone in the thread here is welcome to a completed unit 
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
03-06-2008 20:46
skimming back through, I didn't see it mentioned, but you can use the start parameter to tell the rezzed object what channel it should listen on.... also nice is that when testing (rezzing from inventory) it'd default to channel 0
_____________________
| | . "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... | - 
|