Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Short Scripting Article, Need Feedback Please

Squeebee Wakawaka
Newbie Savant
Join date: 22 Feb 2006
Posts: 28
03-07-2007 14:14
Hi All;

I'm trying to write up a few short articles on things I have learned while scripting. If you have a minute please read the following article:

http://www.wakatech.com/articles/lsl-scripting-basics/creating-non-repeating-random-sequences-using-stacks/

And provide feedback. Is it easily readable, does it provide useful information? Would you like to see more like this?

I'd like these to be of use to the community so let me know if you think it is useful and I'll add more on stuff I've learned like using config notecards and whatnot.
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
03-07-2007 20:59
i found it to be written well, it covered everything in a ez to follow manner and you got your goals accross... on the negitive

whatever size font your using for your code PLEASE change it ... it was difficult to read on my 1280x1024 lcd, and impossible on my 1024x768 crt monitor

as far as the code itself...

CODE
 for (i = 0; i < NotecardLines; i++)

for loops are quite abit slower than do/while loops, not evil but slower

i++ is a post incermental operation
which means it keeps track of what i was and what i will be...
++i just adds one, which is less work

CODE
Randomizer = llDeleteSubList(Randomizer, 0, 0);

removing data from list is an intensive process, your reading the entire list,
finding element x, and rebiulding the whole list, why not just point to the next element in the list ?

ok thats about all i see, so ill stop nitpicking your code :) id like to see more articles about scripting, it would help to give ppl reasons and theory rather than the usuall break/fix here on the forums

ps heres my version, it does the same thing, but its quicker and less intense on the sim

CODE

string NOTECARD_NAME = "data rom";
integer TOTAL_LINES;
integer CURRENT_PLACE;
list DATA;

make_random(){DATA = llListRandomize(DATA, 1);}

default
{
state_entry()
{
llGetNumberOfNotecardLines(NOTECARD_NAME);
}

dataserver(key req_id, string result)
{
if (DATA == [])
{
TOTAL_LINES = ((integer) result - 1);

do
{
DATA += CURRENT_PLACE;
++CURRENT_PLACE;
}

while (CURRENT_PLACE <= TOTAL_LINES);
CURRENT_PLACE = 0;
make_random();
}

else
{
llOwnerSay(result);

if (CURRENT_PLACE < TOTAL_LINES)
{
++CURRENT_PLACE;
}

else
{
CURRENT_PLACE = 0;
make_random();
}
}
}

touch_start(integer na)
{
integer LINE = llList2Integer(DATA, CURRENT_PLACE);
llGetNotecardLine(NOTECARD_NAME, LINE);
}
}
Squeebee Wakawaka
Newbie Savant
Join date: 22 Feb 2006
Posts: 28
03-08-2007 07:21
Thanks for the feedback! I've bumped the font size on the sample code. I was not aware of the ++i/i++ difference and I think the check for Randomizer == [] will be faster than a length check by far.

I've updated the sample as follows:

CODE

state Random
{
state_entry()
{
integer i;

if ( Randomizer == [] ) // IS THE STACK EMPTY?
{
for (i = 0; i < NotecardLines; ++i) // FILL THE STACK
{
Randomizer += ;
}
Randomizer = llListRandomize(Randomizer, 1); // RANDOMIZE THE STACK
}

NotecardLine = llList2Integer(Randomizer, 0); // PULL THE LINE NUMBER FROM THE FRONT OF THE STACK
Randomizer = llDeleteSubList(Randomizer, 0, 0); // POP OFF THE FRONT OF THE STACK
QueryID = llGetNotecardLine(NotecardName, NotecardLine); // READ THE LINE INFORMATION
}

dataserver(key query_id, string data)
{
CurrentMovie = GetMovieInfo(data); // FORMAT THE NOTECARD DATA INTO A GLOBAL
NextState = "Random"; // COME BACK TO RANDOM MODE AFTER PLAYING
state InProgress; // PLAY THE MOVIE
}
}


I appreciate the cost in deleting the front element but if you don't delete it you don't have a stack and the articles ceases to exist in a puff of logic ;) I'd rather preserve the principle at the cost of performance.

Again, thank you very much for the feedback! For loops are really that broken in SL? I'd have thought such a simple construct would be efficient. You'll have to forgive me, I'm relatively new to LSL development but I try to be as sim-friendly as I can.