Jump to content

Multiple Touch Sensing


EnCore Mayne
 Share

You are about to reply to a thread that has been inactive for 630 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

i have a HUD with a multitude of prims that when touched cause all hell to break loose. figuratively, of course, glad you were paying atttention.

anywho, the way i've managed to script the activities is with an if statement. it's all i know.

eg.
      if ( touched == primName1) do customfunction(string1);
      else if (touched == primName2) do customfunction(string2);
      ...
      else if (touched == primName12) do customfunction(string12);

you get the picture.

here's where your help could be enlisted. there's gotta be a simpler method of sensing the HUD's touched object so i don't have to write out 12 separate if statements. i'm lost when it comes to lists but i can hurt my brain enough for just long enough to use their mojo if that's what it will take. i was thinking (with my very limited knowledge) that i could append a variable 1 to 12 in one if statement so that all touches 1 through 12 could be sensed. something like if (touched == nameX) do customfunction(stringX);

anyone?

Edited by EnCore Mayne
too many fingers
Link to comment
Share on other sites

1 hour ago, EnCore Mayne said:

if(touched == nameX) do customfunction(stringX);

list search =
[ "myString1",
  "myString2",
  "..."
];
list do_thing =
[ "myAction1",
  "myAction2",
  "..."
]
integer index = llListFindList(search,[nameX]);
if(index==-1) { /* touched a bad thing */ }
else customFunction(llList2String(do_thing,index));

In practice I'd probably re-work things such that "nameX" and "stringX" are identical, and I wouldn't use this paradime unless 'customFunction' does something intrinsic to strings or whatever type is in do_list, (example, saying the string, moving to a position given by a vector argument in do_thing) because otherwise you're just moving the if(string==string) { do thing } structure into the function.

Edited by Quistess Alpha
  • Thanks 1
Link to comment
Share on other sites

If the string you give to the custom function is just the prim name, all of your if-else checks can be reduced to a single customfunction(touched) with no checks.

If there are prims in the hud that should not act as buttons, you can check for those first and simply return from the event before the function call.

Edited by Wulfie Reanimator
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

yes, i've named the touchable HUD prims to equate to the string necessary for the customfunction(). as in, touch detect objectname1 sends objectname1 to the function.

if ( (string)llGetLinkPrimitiveParams ( llDetectedLinkNumber(0), [PRIM_NAME] ) == "rest1" ) customfunction("rest1");

i've managed to prevent any of the other prims in the HUD from firing with some conditional woojee.

hmmm. i just noticed something in the code i've not implemented which gets me to where your input should take this Wulfie.

touch_start(integer num) {
    integer LinkNum = llDetectedLinkNumber(0);
    string TabName = llGetLinkName(LinkNum);

    ...;

so all's i have to do to catch up all the named objects is this:

if ( (string)llGetLinkPrimitiveParams ( llDetectedLinkNumber(0), [PRIM_NAME] ) == TabName ) customfunction(TabName);

seems plausible. now that i'm thinking about it, i never had a way to manage any number of excessive, or additional decorative prims i might add. i relied on the if(specific name) wasn't touched then return; now that any and all objectnames are live...how was it i was gonna weed those out?

Link to comment
Share on other sites

1 hour ago, EnCore Mayne said:

yes, i've named the touchable HUD prims to equate to the string necessary for the customfunction(). as in, touch detect objectname1 sends objectname1 to the function.

if ( (string)llGetLinkPrimitiveParams ( llDetectedLinkNumber(0), [PRIM_NAME] ) == "rest1" ) customfunction("rest1");

i've managed to prevent any of the other prims in the HUD from firing with some conditional woojee.

hmmm. i just noticed something in the code i've not implemented which gets me to where your input should take this Wulfie.

touch_start(integer num) {
    integer LinkNum = llDetectedLinkNumber(0);
    string TabName = llGetLinkName(LinkNum);

    ...;

so all's i have to do to catch up all the named objects is this:

if ( (string)llGetLinkPrimitiveParams ( llDetectedLinkNumber(0), [PRIM_NAME] ) == TabName ) customfunction(TabName);

seems plausible. now that i'm thinking about it, i never had a way to manage any number of excessive, or additional decorative prims i might add. i relied on the if(specific name) wasn't touched then return; now that any and all objectnames are live...how was it i was gonna weed those out?

Well, there's a couple ways to go about it.

Personally I would completely finish the HUD's appearance first, so you know can structure the prims in a way that's easy to script around. For example, all of the buttons are linked right after the root. That would allow you to filter out any "decorations" by ignoring any link number higher than 13 (assuming you have 12 buttons + root).

Another way would be a single list that contains all of the prim names. You could then check if llGetLinkName exists in that list (using llListFindList). If the name exists, you call customfunction with the prim's name. This way you won't have to worry about link numbers.

I can write a more specific example after I get home. Actually, it's almost exactly what Quistess already showed, just without the second list.

Edited by Wulfie Reanimator
  • Thanks 1
Link to comment
Share on other sites

59 minutes ago, EnCore Mayne said:

if ( (string)llGetLinkPrimitiveParams ( llDetectedLinkNumber(0), [PRIM_NAME] ) == "rest1" ) customfunction("rest1");

Since the prim name is the string you are passing to the function, you can simplify that to just:  customfunction(llGetLinkName(DetectedLinkNumber(0)));

If you want to filter out other non-button linked prims, another approach would be prefixing the button prims' names with a special bit of text to identify them as such. Then in the touch_start event, you would first inspect the name of the clicked prim and see if it contains the special text at the beginning. If it does, strip that out and pass the remainder to the custom function.

Something like

// name button prims something like "KEYWORD_button1"
default
{
    touch_start(integer total_number)
    {
        string s = llGetLinkName(llDetectedLinkNumber(0));
        integer x = llSubStringIndex(s,"KEYWORD");
        if(x==0)
        {
            s = llDeleteSubString(s,0,6);   //adjust end to encompase whatever keyword you use
            llOwnerSay("'"+s+"'");          //example output would be "_button1"
            //customfunction(s);
        }
    }
}

 

Edited by Fenix Eldritch
clarification
  • Thanks 1
Link to comment
Share on other sites

12 hours ago, Wulfie Reanimator said:

...
Personally I would completely finish the HUD's appearance first, so you know can structure the prims in a way that's easy to script around. For example, all of the buttons are linked right after the root. ...

i have, and will continue, hating the method of backwards sorting the various elements of the design links so they follow an unknown order that's not been set in the script yet. perhaps it's bad scripting practise calling for remedial training, but; as the historical foundations have already been set, i will most likely remain quixotic in fashioning said multilink designs. in other words, by the time my script associates any connection to any particular link, or should i, in all likelihood add more prims, i have to unlink, then relink in an opposite order than what i've written. it's mind boggling and i've committed myself to never using manually linked numbers. i just drag select, unselect root, reselect root and let the link numbers fall where they may.

11 hours ago, Fenix Eldritch said:

Since the prim name is the string you are passing to the function, you can simplify that to just:  customfunction(llGetLinkName(DetectedLinkNumber(0)));

If you want to filter out other non-button linked prims, another approach would be prefixing the button prims' names with a special bit of text to identify them as such. Then in the touch_start event, you would first inspect the name of the clicked prim and see if it contains the special text at the beginning. If it does, strip that out and pass the remainder to the custom function....

this method is workable (i think). i'll try it out when i get back inworld. thanks Fenix.

a new day:
=================================
tested, tried, and true:

        if (conditonfortouchability ==1) {
            if ( llSubStringIndex( llGetLinkName(llDetectedLinkNumber(0)), "rest") != -1 ) {
                if ( (string)llGetLinkPrimitiveParams ( llDetectedLinkNumber(0), [PRIM_NAME] ) == TabName ) customfunction(TabName);
            }
            return;
//if "rest" characters not in primname string
        }

Edited by EnCore Mayne
new information, man
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 630 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...