Difference between revisions of "Category talk:LSL User-Defined Functions"

From Second Life Wiki
Jump to navigation Jump to search
 
(Update to add missing signature to original post. Also added self-discovered resolution.)
Line 27: Line 27:
</syntaxhighlight>
</syntaxhighlight>
Appreciate any help or direction!
Appreciate any help or direction!
[[User:Takura Thielt|Takura Thielt]] ([[User talk:Takura Thielt|talk]]) 13:46, 26 July 2024 (PDT)
:Edit: I know I could have, and arguably should have just attempted this ISL myself, but I was hoping there might just be some special syntax that I wasn't thinking of. After some discussion elsewhere, I've learned this isn't available in LSL (as perhaps should have been evidenced by the fact that we sometimes need to pass empty/blank variables to built-in functions.)
:So, for my example above, I'll just have to do the same - that is, passing the second variable as an empty string, or else, as was suggested, try utilizing JSON functions. (Also, please forgive me as I'm learning Wiki formatting, lol. I suspect I may not be doing this properly.) [[User:Takura Thielt|Takura Thielt]] ([[User talk:Takura Thielt|talk]]) 13:46, 26 July 2024 (PDT)

Revision as of 12:46, 26 July 2024

Optional (and/or Default) Parameters

Hi, just wondering if LSL has the ability to support optional parameters for UDF's?

As example, I'm wanting to create a function that passes commands between attachments. I want this function to always take a "command" variable, and optionally may also take relevant "parameter" variable(s). Something vaguely like this, for a weapon and HUD...

integer ACCESSORY_COMMAND_CHANNEL = 10;
key OWNER_KEY;
    
accessoryCommand(string cmd, string param = "")
{
    llRegionSayTo(OWNER_KEY, ACCESSORY_COMMAND_CHANNEL, cmd + ":" + param);
}

default
{
    state_entry() {
        OWNER_KEY = llGetOwner();
    }
    
    touch_start(integer num) {
        accessoryCommand("primary_attached");
        accessoryCommand("ammo", "30");
    }
}

Appreciate any help or direction! Takura Thielt (talk) 13:46, 26 July 2024 (PDT)

Edit: I know I could have, and arguably should have just attempted this ISL myself, but I was hoping there might just be some special syntax that I wasn't thinking of. After some discussion elsewhere, I've learned this isn't available in LSL (as perhaps should have been evidenced by the fact that we sometimes need to pass empty/blank variables to built-in functions.)
So, for my example above, I'll just have to do the same - that is, passing the second variable as an empty string, or else, as was suggested, try utilizing JSON functions. (Also, please forgive me as I'm learning Wiki formatting, lol. I suspect I may not be doing this properly.) Takura Thielt (talk) 13:46, 26 July 2024 (PDT)