Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Script question...

Jokey Domela
Registered User
Join date: 27 Jul 2005
Posts: 83
10-12-2005 16:55
Is it cool to call subroutine_1 from within subroutine_2?
CODE
subroutine_1(key passed_key) 
{
stuff
}

subroutine_2(string passed_string)
{
stuff
subroutine_1(pass a key);
}

default
{
state_entry()
{
listener goes here
}

listen(integer a, string n, key id, string m)
{
if (m == "sensor")
{
llSensor("",NULL_KEY,AGENT,10,2*PI);
}
subroutine_2(m);
}

sensor(integer total_number)
{
stuff
}
}
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
10-12-2005 17:16
Sure. Your subroutines are really custom functions. So, you can use them as you would use the regular ll-functions.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
10-13-2005 04:59
One thing to bear in mind is legibility... nesting functions *is* a good thing if you need to do it, but it's a bit of a bind sometimes when it comes to troubleshooting and bug hunting. It really will encourage you to comment your code wisely.

That said I recently wrote a piece of code for someone that was moderately complex. I'm pretty sure I had 4 levels of functions within functions within... because for each of them I needed to be able to call them in bits from other places too. Sometimes it works and it's the most elegant and friendly solution, even if it's rarely the most readable!