Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Placement of Function code

Samhain Broom
Registered User
Join date: 1 Aug 2004
Posts: 298
08-26-2004 07:07
When writing a script, is there a certain place to put your own functions? Do they have to be in the front of the script, say, after the global variable casting?

If you put the functions at the end, it would seem like they are out of the way of the main program, or does that not work?

I would experiment with that, but I'm remote at the moment and do not have anything to compile with, so cannot try.

Is there anything that can confirm a compile while you are away from your main system?
_____________________
rm -rf /bin/ladden #beware of geeks bearing grifts
Azelda Garcia
Azelda Garcia
Join date: 3 Nov 2003
Posts: 819
08-26-2004 07:51
Yes, functions and global variables need to be declared (written) before you use them.

This is because the compiler makes a single pass through your code.

The following works:

CODE

integer MyGlobalVariable;

DoSomething()
{
llWhisper( 0, (string)MyGlobalVariable );
}

default
{
state_entry()
{
DoSomething();
}
}



There's nothign that comes with SL that allows you to compile your code outside of SL, but there's no reason why someone couldnt build one.

Azelda
_____________________
Bosozoku Kato
insurrectionist midget
Join date: 16 Jun 2003
Posts: 452
08-26-2004 08:12
keep in mind too that a function cannot call another function that's below it.
CODE

// funcs
do_this()
{
llSay(0, "hi");
}

do_that()
{
do_this();
end_me();
}

end_me()
{
llDie();
}

default
{
state_entry()
{
....
}
}


...this won't compile because do_that() can't call the function below it (end_me()), it could however call the do_this() function. The script will fail to compile if you call functions out of order. Due to how the compiler compiles (as stated above) -- it compiles in order, and the call to the end_me() function is invalid, because, to the compiler, "end_me()" has not yet been declared.

Bos
Samhain Broom
Registered User
Join date: 1 Aug 2004
Posts: 298
08-26-2004 11:50
Ok thanks, I thought that was the case about the declaration.

Also, I think I will try to stay away from having one function call another, but that is good to remember also. =)
_____________________
rm -rf /bin/ladden #beware of geeks bearing grifts