These forums are CLOSED. Please visit the new forums HERE
User Defined Functions |
|
|
Ranos Brumer
Registered User
Join date: 17 May 2008
Posts: 9
|
01-11-2009 13:23
Is it possible to get some info on User Defined Functions, what you can and can't do with them?
|
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
01-11-2009 14:09
you just define them in your global name space along with your global varibles
ie dostuff() { code } you can also pass it varibles ie dostuff(name) { if (name = name) { blah blah blah; } } in your state / event you would do something like dostuff("osgeld barmy" ![]() or you can have it return values ie dostuff(name) { if (name = name) { return(true); } } in your state / event you would do something like if (dostuff("osgeld barmy" )ect and you can pretty much do anything you can in any event |
|
Ranos Brumer
Registered User
Join date: 17 May 2008
Posts: 9
|
01-11-2009 14:18
I know how to define them and trigger them just fine.
ok returning a variable is where I am in need of more explanation. Can I have it return a list so I can say do this list lThisList = DoStuff(name); ? |
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
01-11-2009 14:23
yes
just make a local list inside the udf, do all your work there, and return the local list |
|
Ranos Brumer
Registered User
Join date: 17 May 2008
Posts: 9
|
01-11-2009 14:29
ok my next question is then, can you only return one variable or can you return more?
|
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
01-11-2009 14:37
1 afaik
course you could just have the udf work on a global variable directly, and then you could biuld a list with multiple values i wish you could return more than one, ive been quite spoiled by that in lua |
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
01-11-2009 14:43
says only one, however you can compose multiple types and variables to a list and return that _____________________
|
| . "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... | - |
|
Ranos Brumer
Registered User
Join date: 17 May 2008
Posts: 9
|
01-11-2009 14:43
You forgot to tell me I had to define the udf as the type I wanted to return. I figured it out though. Here is a script I was working on to learn more about User Defined Functions.
CODE
|
|
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
|
01-11-2009 17:41
You could also benefit by reading the following...
http://www.lslwiki.net/lslwiki/wakka.php?wakka=UserDefinedFunction _____________________
http://slurl.com/secondlife/Together
|
|
Ranos Brumer
Registered User
Join date: 17 May 2008
Posts: 9
|
01-12-2009 08:17
Thanks.
|
|
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
|
01-12-2009 10:41
you can also pass it variables What's the diff? (I know Osgeld knows, this is for the peanut gallery.) If we were passing variables (a.k.a, "pass by reference" , a function could modify a passed variable. That is:CODE
If we passed variables, this code would chat "A". But, in LSL, we cannot; we can only pass values. Changes to values don't get propagated back to the variables that had earlier held them. This concludes today's lecture. ![]() |
|
Cappy Frantisek
Open Source is the Devil!
Join date: 27 Oct 2006
Posts: 400
|
01-12-2009 12:20
Just to quibble, you can't pass variables, you can only pass values. What's the diff? (I know Osgeld knows, this is for the peanut gallery.) If we were passing variables (a.k.a, "pass by reference" , a function could modify a passed variable. That is:CODE
If we passed variables, this code would chat "A". But, in LSL, we cannot; we can only pass values. Changes to values don't get propagated back to the variables that had earlier held them. This concludes today's lecture. ![]() Now that takes me back to the old programming classes, thanks! ![]() |
|
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
|
01-12-2009 18:08
/me straightens his bow tie and grins.
![]() |
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
01-13-2009 16:34
I know Osgeld knows, this is for the peanut gallery i did, but wow, you put way too much faith in my knowledge lol |
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
01-14-2009 12:11
to get around that, you can have the function operate on a global and return nothing as Os mentioned earlier
_____________________
|
| . "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... | - |
|
Ranos Brumer
Registered User
Join date: 17 May 2008
Posts: 9
|
05-10-2009 19:31
Hmm sorry for bringing this back up, but I understood what he meant by passing a variable. While I can't exactly quote exact terminology like all of you. I do have programming experience. Just curious about how it was handled in the lsl. Didn't realize it had been 4 months since I last worked on my code. The help here has been more then I expected though. Thanks!
|
|
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
|
05-11-2009 05:17
You may have understood what he said, but what he said, "you can also pass it variables", is false.
It's better to say what's true than to say something false, even if many people will still get the right idea. Accuracy is important. What he meant to say was simply "you can also pass it values". This isn't criticism or chop-busting, it's just a correction in the interest of accuracy. I make mistakes in my posts all the time, and I really appreciate it when others correct me. |
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
05-11-2009 09:46
You may have understood what he said, but what he said, "you can also pass it variables", is false. It's better to say what's true than to say something false, even if many people will still get the right idea. Accuracy is important. What he meant to say was simply "you can also pass it values". This isn't criticism or chop-busting, it's just a correction in the interest of accuracy. I make mistakes in my posts all the time, and I really appreciate it when others correct me. seconded... much as I hate screwing up, I hate hate not knowing I did more. _____________________
|
| . "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... | - |