Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

If I knew then what I know now...

Blazin Aubret
Registered User
Join date: 23 Feb 2006
Posts: 18
11-04-2007 01:34
Hiya everyone:D

Beginning little eenie weenie baby scripter here haha! I'm very into it though and have been working my heart out practicing.

My question to all of you more experienced scripters is this: What fact, common sense, bug, whatever it is..do you know about now, that you wish you knew when you first started scripting?

I'm hoping maybe I can learn some simple things from you guys that maybe I or any other beginning scripter would'nt be able to learn elsewhere.

Thanks for any help in advance and much respect to all of you!
Debbie Trilling
Our Lady of Peenemünde
Join date: 17 Oct 2006
Posts: 434
11-04-2007 02:19
This recent thread might cover some of what you are asking :)

/54/92/217724/1.html
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
Pale on LSL
11-04-2007 04:00
I think there are two basics to really grasp:

Events
Event Handlers

LSL is an Event Driven language. This is a very specific 'genre' of language... you can look it up:

I think the biggest mistake with an Event Driven language is to treat it as a Flow Driven language. Being able to picture your script in the context of a queue of events waiting to happen - with a sequence which you may, or may not, be able to predict - I think is the biggest leap.

Even having grasped that I think the next challenge is to understand that some LSL functions themselves trigger events. A classic example would be llGetNotecardLine. It doesn't get a notecard line. It queues an event. The dataserver Event Handler gets the notecard line. Even more fun you don't absolutely know when that event will occur and other events may occur in the mean time.

Trying to read a notecard in a while loop is a Flow Driven approach to an Event Driven problem - it will drive you insane - but it is a very easy mistake to make.

Event logic has to be strangely fuzzy as it reacts to the environment around it rather being able to fully control its input. Therein lies the Art of Programming in an Event Driven world and where the reference manuals won't help you very much.

Most LSL functions are flow-driven (I don't think it's possible to have a language without a flow-driven element). For example, llGetOwner happens immediately. Understanding which is which can save you considerable hair loss. :p

How do you know which is which? You don't. :) You have find the reference material which, in this respect, will help you a lot.
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
11-04-2007 15:31
You don't have to create something totally new, because 90% of scripts with any sophistication will have design tradeoffs, which you can make in a different direction to the competition.

... Um, or is it only allowed to be something about writing the code? :)
Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
11-07-2007 02:42
All the scripts have to deal with 16000 bytes of memory. Unfortunately the LSL compiler does not make any optimization.

So the 2 scripts here do the same but take different size in memory.. It is significant enough to be of help when you are struggling to squeeze the last bytes of datas in your code:
***************************************************************************
default
{
state_entry()
{
}

touch_start(integer total_number)
{
llSay(0, "1-Free memory="+(string)llGetFreeMemory());

integer a = FALSE ;
integer b = TRUE ;
if (a)
{
llSay(0, "1-a is TRUE";) ;
}
if (b)
{
llSay(0, "1-b is TRUE";) ;
}
if (!a)
{
llSay(0, "1-a is FALSE";) ;
}
if (!b)
{
llSay(0, "1-b is FALSE";) ;
}
}
}
********************************************************************
default
{
state_entry()
{
}

touch_start(integer total_number)
{
llSay(0, "2-Free memory="+(string)llGetFreeMemory());

integer a = FALSE ;
integer b = TRUE ;
if (a==TRUE)
{
llSay(0, "2-a is TRUE";) ;
}
if (b==TRUE)
{
llSay(0, "2-b is TRUE";) ;
}
if (a==FALSE)
{
llSay(0, "2-a is FALSE";) ;
}
if (b==FALSE)
{
llSay(0, "2-b is FALSE";) ;
}
}
}

********************************************************

Put the 2 scripts in same or different boxes and try away

2:40] Object: 1-Free memory=15865
[2:40] Object: 1-b is TRUE
[2:40] Object: 1-a is FALSE
[2:40] Object: 2-Free memory=15874
[2:40] Object: 2-b is TRUE
[2:40] Object: 2-a is FALSE

9 bytes isn't much but it's still 0.5% of your total memory in 4 tests, so if you have a lot more tests you can gain a lot of memory back.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-07-2007 03:37
Look at else if in the wiki and you will see that you can also write it like this and save even more:

CODE

default
{
state_entry()
{
}

touch_start(integer total_number)
{
llSay(0, "2-Free memory="+(string)llGetFreeMemory());

integer a = FALSE ;
integer b = TRUE ;
if (a)
{
llSay(0, "2-a is TRUE") ;
}
if (b)
{
llSay(0, "2-b is TRUE") ;
}
if (!a)
{
llSay(0, "2-a is FALSE") ;
}
if (!b)
{
llSay(0, "2-b is FALSE") ;
}
}
}


[3:35] Object: 2-Free memory=15900
[3:35] Object: 2-b is TRUE
[3:35] Object: 2-a is FALSE
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
11-07-2007 04:22
Yeah this is the same than my first script. The memory displayed varies I believe it is when you add or remove scripts in the same prim.

[4:26] Object: 2-Free memory=15874
[4:26] Object: 2-b is TRUE
[4:26] Object: 2-a is FALSE
[4:27] Object: 1-Free memory=15900
[4:27] Object: 1-b is TRUE
[4:27] Object: 1-a is FALSE

So yeah 26 bytes difference even better.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-07-2007 04:50
Ah heck I am sorry Twisted. Blinders on this morning and before caffiene kicked in.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
11-07-2007 04:52
Well, I'm sorry too I posted incorrect results.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-07-2007 04:59
Well I am sorry that you are sorry.

Ah much better. Morning silliness out of the way and I can face the day. Now it truly is time for work.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
11-07-2007 05:51
More optimization can be done by removing the nested else if in tests:

*****************************************************************
default
{
state_entry()
{
}

touch_start(integer total_number)
{
string message = "blah" ;

llSay(0, "2-free memory="+(string)llGetFreeMemory()) ;

if (message == "here";)
{
llSay(0, "messag="+message);
}
else if (message == "i";)
{
llSay(0, "messag="+message);
}
else if (message == "am";)
{
llSay(0, "messag="+message);
}
else if (message == "checking";)
{
llSay(0, "messag="+message);
}
else if (message == "different";)
{
llSay(0, "messag="+message);
}
else if (message == "strings";)
{
llSay(0, "messag="+message);
}
}
}
***************************************************************************
default
{
state_entry()
{
}

touch_start(integer total_number)
{
string message = "blah" ;

llSay(0, "1-free memory="+(string)llGetFreeMemory()) ;

if (message == "here";)
{
llSay(0, "messag="+message);
}
if (message == "i";)
{
llSay(0, "messag="+message);
}
if (message == "am";)
{
llSay(0, "messag="+message);
}
if (message == "checking";)
{
llSay(0, "messag="+message);
}
if (message == "different";)
{
llSay(0, "messag="+message);
}
if (message == "strings";)
{
llSay(0, "messag="+message);
}
}
}
**************************************************************************

From: someone

5:45] Object: 1-free memory=15737
[5:45] Object: 1-free memory=15702
[5:45] Object: 1-free memory=15698
[5:45] Object: 1-free memory=15698
[5:45] Object: 1-free memory=15698
[5:45] Object: 2-free memory=15712
[5:45] Object: 2-free memory=15677
[5:45] Object: 2-free memory=15673
[5:45] Object: 2-free memory=15673
[5:45] Object: 2-free memory=15673


You have to click a few times to get the free memory check to stabilize... So nested else if take more memory, you gain 5 bytes for each removed. On the other hand it is safer and faster to use nested else if. It is a last resort trick.