steph Arnott Posted March 20, 2016 Share Posted March 20, 2016 Could one of you clever ladies and gent deconstruct say the lllisten and create it as if it was a user created function? The reason i ask is i can not figure out how to create one my self. Have read the wiki a hundred times and am still lost. If it an lsl function i used to then i can get a handle on the creation. Well hopefully.ADDED, Maybe that is more complicated than i think. A simple this that and it does this approach maybe better. Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 20, 2016 Share Posted March 20, 2016 A user-created function cannot do anything that isn't already done by standard LSL functions. So, you can't invent a new way to do llListen. User defined functions allow you to streamline your use of basic LSL functions in customized combinations, though. So, for example, you could create a very simple function that opens a dialog and guarantees that you don't already have a listener open for another person's responses: OpenDialog(key NewAv){ llListenRemove(gLsn); gChan = (-1) * (integer)llFrand(1000000.0) - 278; gLsn = llListen(gChan,"","",NewAv); llDialog(NewAv," \n What would you like to do next?",gPossibilities,gChan);} Then you'd have a simple packet of functions that you could re-use in many spots in your script instead of typing them in line over and over again. The im,portant thing is that you could have done those as separate command lines. The user-defined function just gives you a way to package them conveniently. EDIT: I wish I could type something without making typos. Link to comment Share on other sites More sharing options...
steph Arnott Posted March 20, 2016 Author Share Posted March 20, 2016 Use functions just never put stuff between the (), BTW just said the listen as i could nio figure a way to decribe what i meant. I will run that and examples, maybe i thinking it beyond me and is just simple.Have been avoiding it, but canning a user defined function would be helpful than writing it in every other script when needed. Link to comment Share on other sites More sharing options...
steph Arnott Posted March 20, 2016 Author Share Posted March 20, 2016 I post one in a few days then you can say what wrong and what would be better. To late now for it, brain gone to sleep.Nite be well Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 20, 2016 Share Posted March 20, 2016 BTW, the other big use for user defined functions is to return some calculated value. For example, the common function that many LSL scripters use to put dialog buttons in a decent order looks like this: list OrderButtons(list vLstRtn){ return //-- fix the order to L2R/T2B llList2List( vLstRtn, -3, -1 ) + llList2List( vLstRtn, -6, -4 ) + llList2List( vLstRtn, -9, -7 ) + llList2List( vLstRtn, -12, -10 );} You feed it your unordered list, vLstRtn, and it returns a nicely ordered one to the spot where you called the function in your script, as in llDialog(llDetectedKey(0),"\n Pick one!", OrderButtons(my_list), gChan); Link to comment Share on other sites More sharing options...
steph Arnott Posted March 20, 2016 Author Share Posted March 20, 2016 Will study this, i think i was expecting something wonderfull. But i could condence some of my functions, well simplyfy them. I clearly have not valued my own functions thinking that i should have had integers and what ever in the "a function(whsatever)" part. Well at least i not as backward as i had thought. Will exeriment with basics and see what i can use over what nomaly. which is a_function() { stuff here } Link to comment Share on other sites More sharing options...
Qwalyphi Korpov Posted March 21, 2016 Share Posted March 21, 2016 Sixty two examples of user functions can be found here: http://wiki.secondlife.com/wiki/Category:LSL_User-Defined_Functions Link to comment Share on other sites More sharing options...
steph Arnott Posted March 21, 2016 Author Share Posted March 21, 2016 Thanks, i did read all that. I was under some impression that the fucntions i write were wrong, but in fact most can not be done by inserting stuff in function defenition part. Though i do need to think in future as to whether i could use that route for simpler functions. Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 21, 2016 Share Posted March 21, 2016 If you're familar with other programming languages, think of a user defined function as a subroutine -- a block of statements that can be executed globally. I used to have a huge library of Fortran subroutines for numerical analysis that I could just drop into whatever program I was writing, to save myself the trouble of figuring out how to solve a set of simultaneous differential equations or whatever each time. Link to comment Share on other sites More sharing options...
Xiija Posted March 21, 2016 Share Posted March 21, 2016 another use for user functions, as in an item that gives you a folder when you rez OR wear your purchase/gift... ( i wish more merchants would do this ... so you can get the folder in a no rez zone ) Give_ALL () { key owner = llGetOwner(); list inventoryItems; integer inventoryNumber = llGetInventoryNumber(INVENTORY_ALL); integer index; for ( ; index < inventoryNumber; ++index ) { string itemName = llGetInventoryName(INVENTORY_ALL, index); if (itemName != llGetScriptName() ) { if (llGetInventoryPermMask(itemName, MASK_OWNER) & PERM_COPY) { inventoryItems += itemName; } else { llGiveInventory(owner, itemName); // 2.0 seconds delay } } } if (inventoryItems != [] ) llGiveInventoryList(owner, llGetObjectName(), inventoryItems); // 3.0 seconds delay } Default { state_entry() { Give_ALL (); } attach(key id) { if (id) // is a valid key and not NULL_KEY { Give_ALL (); } } on_rez(integer start_param) { Give_ALL (); } } Link to comment Share on other sites More sharing options...
steph Arnott Posted March 22, 2016 Author Share Posted March 22, 2016 Thanks for the info. Link to comment Share on other sites More sharing options...
Estelle Pienaar Posted March 30, 2016 Share Posted March 30, 2016 Yingzi did a great explanation when I asked a few Months back. Scroll to the bottom of the post: https://community.secondlife.com/t5/LSL-Scripting/User-defined-functions-for-dummies/td-p/2805242 Link to comment Share on other sites More sharing options...
steph Arnott Posted March 30, 2016 Author Share Posted March 30, 2016 Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
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