Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Assigning var values in a functions

revochen Mayne
...says
Join date: 14 Nov 2006
Posts: 198
01-15-2009 11:51
Greetings =)

Did you know that its possible to assign a variables value in a function where the parameters belongs to? I know its common practice at other programming languages and discoverd it as i just tried it out.
I guess its new since Mono is in use but wonder if even Lindens do know about that feature yet. ^^

Example:
CODE

string gText = "this text will never show up";

default
{
state_entry()
{
llOwnerSay(gText="but this text will); // assigning a new text to a variable and using it the same time
}
}
CODE


I know that post and pre increments works within functions, also calculations (without assigning) but this was new and i've never seen this used at any script or the LSL Wiki.
To know this might help to reduce line of codes allthough i believe there are not many situations for that.
_____________________
www.HotFusion-SL.com
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-15-2009 15:56
yup, I find it useful for flag switching

gBooSwitch = !gBooSwitch <-- swaps every time you go through the statment

another useful one for looping backward through various event queues

while ( count ){
someVar = lldetected*( --count );
//-- do other stuff
}
_____________________
|
| . "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...
| -