|
Fenix Eldritch
Mostly harmless
Join date: 30 Jan 2005
Posts: 201
|
11-02-2008 09:46
I'm working on a hud that takes advantage of llDetectedTouchST() to reduce the number of prims/scripts for buttons. This script I made divides the root prim's face into 6 clickable regions and changes the texture to simulate a button being highlighted when clicked. I've got it working but for some reason in addition to responding to clicks on the root prim, it also somehow responds when I click on the child prims of the hud as well. No other scripts exist in the hud. The only thing I can think of as causing this is that in my first attempt, I tried using llDetectedTouchUV() instead. this was because two of the regions have different buttons depending on the mode the hud is in. But I've recompiled the script many times since that change.... Any ideas on what's causing this? // *** Global Variables *** \\ integer magMode; integer currentButton;
// *** User-defined Functions *** \\
integer detectButton(vector v) // Determin which button is touched via defined ranges { integer bnum; if(magMode) //magic mode { if(v.x<0.161) {llSay(0,"Green clicked."); bnum = 0;} else if (v.x>0.172 && v.x<0.327) {llSay(0,"Red clicked."); bnum = 1;} else if (v.x>0.337 && v.x<0.495) {llSay(0,"Purple clicked."); bnum = 2;} else if (v.x>0.505 && v.x<0.662) {llSay(0,"Blue clicked."); bnum = 3;} else if (v.x>0.672 && v.x<0.829) {llSay(0,"Yellow clicked."); bnum = 4;} else if (v.x>0.842) {llSay(0,"Silver clicked."); bnum = 5;} } else // items mode { if(v.x<0.161) {llSay(0,"Item1 clicked."); bnum = 6;} else if (v.x>0.172 && v.x<0.327) {llSay(0,"Item2 clicked."); bnum = 7;} } llSetPrimitiveParams([PRIM_TEXTURE, ALL_SIDES, TEXTURE-UUID, <0.372,0.05,0.0>, <-0.308,(-0.008-(bnum*0.0549)),0>, 0]);
return bnum; }
// *** States *** \\ default { state_entry() { llSetPrimitiveParams([PRIM_TEXTURE, ALL_SIDES, TEXTURE-UUID, <0.372,0.05,0.0>, <-0.308,-0.008,0>, 0]); currentButton = 0; magMode = TRUE; }
touch_start(integer num_detected) { vector pos = llDetectedTouchST(0); // llSay(0,(string)pos); integer clickedButton = detectButton(pos); } }
|
|
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
|
11-02-2008 10:14
Touch events for child prims are sent to scripts in the root prim unless you put a script in each child prim that has an empty touch*() event handler (and no llPassTouches(TRUE) in it).
As such, llDetectedTouch*() functions will give a script in the root prim the info on child prim touches.
This is normal and expected behavior.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
11-02-2008 10:27
I would consider using llDetectedLinkNumber() to filter for the touches you want to respond to instead of putting dummy scripts in the child prims. See http://www.lslwiki.net/lslwiki/wakka.php?wakka=llDetectedLinkNumber
|
|
Fenix Eldritch
Mostly harmless
Join date: 30 Jan 2005
Posts: 201
|
11-02-2008 10:41
Ahh, that makes sense now. I'm working on the hud in parts, and a second piece uses this code very similarly, but it was in a child prim at the start. So when I suddenly saw "different" behavior in this part, I immediately thought it was some bug.
changing the link order such that the button prim is no the root gets the behavior I wanted.
Thanks!
|
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
11-03-2008 05:11
Hmmm, I'll make it more apparent in the documentation that the user needs to pay attention to the link number.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
11-03-2008 20:23
I've added some text to the description footnote. https://wiki.secondlife.com/w/index.php?title=LlDetectedTouchST&diff=129162&oldid=95330From: someone The prim that was touched may not be the prim receiving the event, use llDetectedLinkNumber to check for this; likewise you can use llDetectedTouchFace to determine which face was touched. I'm not sure if it belongs this high up on the page but ehhh.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|