|
View:
New views
16 Messages
—
Rating Filter:
Alert me
|
|
|
Complex scripts and good styleThis is really a question about style and
efficiency in scripting. I have an object that needs to respond to lots of
events - having notecards dropped on it, parsing strings in chat, being touched,
menus, scanning for nearby objects and so on. Is the best way of handling this
to have one large script with lots of events and functions in? Some of the
parsing functions (extracting dates from text strings and formatting them, for
instance) are quite complex, so I have quite a few functions that are 20 or so
lines of script each.
If I put it all in one script in the root prim, the
script will be several hundred lines long. Is this bad practice, or is it better
to distribute my scripts among prims in the object (it will be a HUD, so
consists of a few linked prims) so that I have lots of different shorter
scripts spread over a few prims? For example, when it hears text in chat it
could send a linked message to another prim that will do the work of decoding
the message and sending the result back to the root prim. Or is it OK to have a
large script that does what I want it to in the root prim?
Maxxi.
_______________________________________________ Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
|
|
Re: Complex scripts and good styleDon't forget you can also do it with multiple scripts in the same prim.
Most of us got into the habit of thinking that scripts must be tiny in pre-Mono times. Nowadays, though, I don't think there's any problem with a script several hundred lines long. Although I don't have any that big myself. As a matter of personal style you may prefer to break it up, but that's up to you. On Thu, Oct 15, 2009 at 6:58 AM, Maxxi Short <maxxi@...> wrote: > This is really a question about style and efficiency in scripting. I have an > object that needs to respond to lots of events - having notecards dropped on > it, parsing strings in chat, being touched, menus, scanning for nearby > objects and so on. Is the best way of handling this to have one large script > with lots of events and functions in? Some of the parsing functions > (extracting dates from text strings and formatting them, for instance) are > quite complex, so I have quite a few functions that are 20 or so lines of > script each. > > If I put it all in one script in the root prim, the script will be several > hundred lines long. Is this bad practice, or is it better to distribute my > scripts among prims in the object (it will be a HUD, so consists of a few > linked prims) so that I have lots of different shorter scripts spread over a > few prims? For example, when it hears text in chat it could send a linked > message to another prim that will do the work of decoding the message and > sending the result back to the root prim. Or is it OK to have a large script > that does what I want it to in the root prim? > > Maxxi. > > _______________________________________________ > Click here to unsubscribe or manage your list subscription: > https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters > > Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
|
|
Re: Complex scripts and good styleHowever, every script, and every event has a bit of overhead on the sim, which would suggest that, in general, longer scripts rather than more scripts works just fine and possibly better in the wider sense. I did have the tools for a simple (non-networked) vendor I wrote to see the difference and after the additional llDetectedTouch* functions came along changed from a multi-script to a single script vendor. Each one lost about 8 events and 4 scripts. The savings for a single vendor were just about detectable on the sim, but as soon as I had 70 of them in a shop, it was really pretty noticeable. I tend to keep my scripts into one larger script where possible in part because of this and in part because I find it easier to debug that way rather than to debug across dozens of scripts that swap things back and forth - the order of the data transfer isn't really under my control and can cause unexpected problems quite easily. If you find you debug small scripts that talk to each other better, then you probably gain more from that than you lose in the case of a HUD. El. On 15 Oct 2009, at 11:58, Maxxi Short wrote:
SL Education collaboration forum: http://forum.eloisepasteur.net/ _______________________________________________ Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
|
|
Re: Complex scripts and good styleI have read of people having collapsed back to the monolithic one script with no functions model to gain speed, efficiency, and reduced memory. Just makes it as easy to read as old PHP scripts rofl. Given the nature of LSL I am willing to put odds on it is something that must be decided on a case by case basis. Now some LSL functions want to be in scripts in linked prims to avoid built in delays so perhaps thinking in "containers are prims" mode might be useful. I wonder what others think about that aspect. From: Maxxi Short <maxxi@...> To: secondlifescripters@... Sent: Thu, October 15, 2009 6:58:01 AM Subject: Complex scripts and good style This is really a question about style and
efficiency in scripting. I have an object that needs to respond to lots of
events - having notecards dropped on it, parsing strings in chat, being touched,
menus, scanning for nearby objects and so on. Is the best way of handling this
to have one large script with lots of events and functions in? Some of the
parsing functions (extracting dates from text strings and formatting them, for
instance) are quite complex, so I have quite a few functions that are 20 or so
lines of script each.
If I put it all in one script in the root prim, the
script will be several hundred lines long. Is this bad practice, or is it better
to distribute my scripts among prims in the object (it will be a HUD, so
consists of a few linked prims) so that I have lots of different shorter
scripts spread over a few prims? For example, when it hears text in chat it
could send a linked message to another prim that will do the work of decoding
the message and sending the result back to the root prim. Or is it OK to have a
large script that does what I want it to in the root prim?
Maxxi.
_______________________________________________ Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
|
|
Re: Complex scripts and good styleI try to strike the right balance... shorter "utility" scripts that soak up our much-loved SL-applied delays, and
longer scripts to keep the processing model simpler. "simpler": the scripts aren't really running in parallel, and with events not being pre-emptive, I want as few errors introduced as possible by race conditions or odd timing-related errors, *just* because I had to break code into small chunks to avoid memory limitations of SL. I have one project that required a number of smaller scripts, and 18 scripts each 500-800 lines long... and it was manageable. With some control logic to start/stop scripts when you need them, you can even manage the lag impact pretty well. With some forethought to try and avoid "designing myself into a corner", I don't see why that can't be extended to whatever is needed. (The only torturous part of that project was where I absolutely needed to implement some serialization and holdoff logic, and had to build a semaphore/lock mechanism using llMessageLinked. ugh.) - JB On Thu, Oct 15, 2009 at 8:28 AM, Ann Otoole <missannotoole@...> wrote:
_______________________________________________ Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
|
|
Re: Complex scripts and good styleOn Thu, Oct 15, 2009 at 12:58 PM, Maxxi Short <maxxi@...> wrote:
My rule of thumb is - it goes in another script if I need two threads, if I don't have enough memory, or if it needs to be in specific prim. I have scripts with more than 1000 lines inside and don't consider it a problem.
Having as little code as possible in events is good for readability - though it's a bit slower, I prefer having huge functions than huge events (if you can keep functions short even better). Also, code must be properly commented (but not overcommented) - it goes without saying.
_______________________________________________ Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
|
|
Re: Complex scripts and good styleI tend to work on the basis of timing, with separate scripts providing
either Asynchronous multitasking or storage, where needed. Anything that has to be sequential, or cannot afford to wait for link-messages or data-server events go in the core scripts, long-term storage and outbound communication can go in separate threads, and I often have a "Watchdog" script that can reset, start and stop the others to try and keep the whole in synchronisation. Most of my code Post MONO has tended to larger single scripts. _______________________________________________ Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
|
|
Re: Complex scripts and good styleMy AO script is one great big giant 1200-line monster compiled Mono. I
can put in however many stands, sits, etc into it that I'll ever need (who needs 45 stands? not me, but it's ok to do it) and I still have 20k of memory left over. When I need memory I'll usually break things up. Large datasets, etc., etc. Both my question and the root Q of this thread are pretty much the same Q! --GC Dale Innis wrote: > Don't forget you can also do it with multiple scripts in the same prim. > > Most of us got into the habit of thinking that scripts must be tiny in > pre-Mono times. Nowadays, though, I don't think there's any problem > with a script several hundred lines long. Although I don't have any > that big myself. As a matter of personal style you may prefer to > break it up, but that's up to you. > > On Thu, Oct 15, 2009 at 6:58 AM, Maxxi Short <maxxi@...> wrote: > >> This is really a question about style and efficiency in scripting. I have an >> object that needs to respond to lots of events - having notecards dropped on >> it, parsing strings in chat, being touched, menus, scanning for nearby >> objects and so on. Is the best way of handling this to have one large script >> with lots of events and functions in? Some of the parsing functions >> (extracting dates from text strings and formatting them, for instance) are >> quite complex, so I have quite a few functions that are 20 or so lines of >> script each. >> >> If I put it all in one script in the root prim, the script will be several >> hundred lines long. Is this bad practice, or is it better to distribute my >> scripts among prims in the object (it will be a HUD, so consists of a few >> linked prims) so that I have lots of different shorter scripts spread over a >> few prims? For example, when it hears text in chat it could send a linked >> message to another prim that will do the work of decoding the message and >> sending the result back to the root prim. Or is it OK to have a large script >> that does what I want it to in the root prim? >> >> Maxxi. >> >> _______________________________________________ >> Click here to unsubscribe or manage your list subscription: >> https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters >> >> >> > _______________________________________________ > Click here to unsubscribe or manage your list subscription: > https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters > > _______________________________________________ Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
|
|
|
|
|
Re: Complex scripts and good styleAnd as someone else has commented, if I know I'm going to be storing a lot of stuff, I usually use additional scripts for memory scripts - those limits are still pretty tight for storing data in SL and not everyone wants to direct stuff to an outside server for a variety of reasons. El. On 15 Oct 2009, at 17:25, Maxxi Short wrote:
SL Education collaboration forum: http://forum.eloisepasteur.net/ _______________________________________________ Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
|
|
Re: Complex scripts and good styleMany thanks to you Eloise, and to you Very - and
yes, good advice about keeping a local off-SL copy of the source!
So for a memory script do you mean have one of the
prims whose job is basically to receive data - and that's where I can store my
lists? So if my main object wants to store long lists of dates and avatars,
rather than having global list variables in the main script, have those
variables in a script in a separate prim and have the main script send items to
that prim telling it to add/remove from the lists via a linked
message?
Maxxi.
_______________________________________________ Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
|
|
Re: Complex scripts and good styleYou don't have to use separate prims, just separate scripts. Each script
gets x amount (16k in lsl, 64k in mono); it's not per-prim memory. One day I will actually *use* an outside server. Not sure when... I have one with mysql, but... meh. --GC Maxxi Short wrote: > Many thanks to you Eloise, and to you Very - and yes, good advice > about keeping a local off-SL copy of the source! > > So for a memory script do you mean have one of the prims whose job is > basically to receive data - and that's where I can store my lists? So > if my main object wants to store long lists of dates and avatars, > rather than having global list variables in the main script, have > those variables in a script in a separate prim and have the main > script send items to that prim telling it to add/remove from the lists > via a linked message? > > Maxxi. > > > ----- Original Message ----- > *From:* Eloise Pasteur <mailto:eloisepasteur@...> > *To:* Maxxi Short <mailto:maxxi@...> > *Cc:* secondlifescripters@... > <mailto:secondlifescripters@...> > *Sent:* Thursday, October 15, 2009 6:04 PM > *Subject:* Re: Complex scripts and good style > > No, the compiled code has no comments, you're not being naive. > > And as someone else has commented, if I know I'm going to be > storing a lot of stuff, I usually use additional scripts for > memory scripts - those limits are still pretty tight for storing > data in SL and not everyone wants to direct stuff to an outside > server for a variety of reasons. > > El. > > On 15 Oct 2009, at 17:25, Maxxi Short wrote: > >> Many thanks for the responses, they've been really helpful! I >> think my main script will be in the region of 500 lines which I >> thought might be excessive, but Domchi says he has no problems >> with 1,000 line scripts, so I think it would be more efficient to >> have everything that logically belongs to the root in a single >> script. >> >> I do comment quite heavily - I assume that "compilation" strips >> out comments so 500 lines of code and 500 lines of comments would >> be no different to 500 lines of code? Or am I being naive there? >> >> Maxxi. >> > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Click here to unsubscribe or manage your list subscription: > https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters > _______________________________________________ Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
|
|
Re: Complex scripts and good styleHonestly, using a remote database for any serious storage is *so much
better in every way* than having some sort of LSL database solution. It's far easier to write, quicker, more powerful, easier on the sim, and the data will be regularly backed up. By all means cache information locally for speed and in case your remote server goes down but honestly, I can't imagine dealing with any serious database stored with LSL any more. Even a system without a mysql server could use, say, sqlite as long as it has the required version of PHP. This is even more important when scripting for use with Opensim, which I do increasingly these days, since opensims (insert usual disclaimer about how impressive the project is and how great all the developers smell) are liable to go down and reset scripts at the drop of a hat. Keeping as much as possible stored externally means that all the scripts have to do is sync back on reset. This can also be a lot easier on the opensim itself. On 15 Oct 2009, at 22:15, Glen wrote: > You don't have to use separate prims, just separate scripts. Each > script > gets x amount (16k in lsl, 64k in mono); it's not per-prim memory. > > One day I will actually *use* an outside server. Not sure when... I > have > one with mysql, but... meh. > > --GC > > Maxxi Short wrote: >> Many thanks to you Eloise, and to you Very - and yes, good advice >> about keeping a local off-SL copy of the source! >> >> So for a memory script do you mean have one of the prims whose job is >> basically to receive data - and that's where I can store my lists? So >> if my main object wants to store long lists of dates and avatars, >> rather than having global list variables in the main script, have >> those variables in a script in a separate prim and have the main >> script send items to that prim telling it to add/remove from the >> lists >> via a linked message? >> >> Maxxi. >> >> >> ----- Original Message ----- >> *From:* Eloise Pasteur <mailto:eloisepasteur@...> >> *To:* Maxxi Short <mailto:maxxi@...> >> *Cc:* secondlifescripters@... >> <mailto:secondlifescripters@...> >> *Sent:* Thursday, October 15, 2009 6:04 PM >> *Subject:* Re: Complex scripts and good style >> >> No, the compiled code has no comments, you're not being naive. >> >> And as someone else has commented, if I know I'm going to be >> storing a lot of stuff, I usually use additional scripts for >> memory scripts - those limits are still pretty tight for storing >> data in SL and not everyone wants to direct stuff to an outside >> server for a variety of reasons. >> >> El. >> >> On 15 Oct 2009, at 17:25, Maxxi Short wrote: >> >>> Many thanks for the responses, they've been really helpful! I >>> think my main script will be in the region of 500 lines which I >>> thought might be excessive, but Domchi says he has no problems >>> with 1,000 line scripts, so I think it would be more efficient to >>> have everything that logically belongs to the root in a single >>> script. >>> >>> I do comment quite heavily - I assume that "compilation" strips >>> out comments so 500 lines of code and 500 lines of comments would >>> be no different to 500 lines of code? Or am I being naive there? >>> >>> Maxxi. >>> >> >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Click here to unsubscribe or manage your list subscription: >> https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters >> > > _______________________________________________ > Click here to unsubscribe or manage your list subscription: > https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters _______________________________________________ Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
|
|
|
|
|
Re: Complex scripts and good styleOK, I think that makes sense - thanks! Presumably I communicate between the
scripts by using a link message to the same prim? So if I have my big list in script B in the prim, and the main work in script A, script A sends a linked message to THIS_PRIM so that script B can store it? Maxxi. ----- Original Message ----- From: "Glen" <gcanaday@...> To: <secondlifescripters@...> Sent: Thursday, October 15, 2009 10:15 PM Subject: Re: Complex scripts and good style > You don't have to use separate prims, just separate scripts. Each script > gets x amount (16k in lsl, 64k in mono); it's not per-prim memory. > > One day I will actually *use* an outside server. Not sure when... I have > one with mysql, but... meh. > > --GC > > Maxxi Short wrote: >> Many thanks to you Eloise, and to you Very - and yes, good advice >> about keeping a local off-SL copy of the source! >> >> So for a memory script do you mean have one of the prims whose job is >> basically to receive data - and that's where I can store my lists? So >> if my main object wants to store long lists of dates and avatars, >> rather than having global list variables in the main script, have >> those variables in a script in a separate prim and have the main >> script send items to that prim telling it to add/remove from the lists >> via a linked message? >> >> Maxxi. >> >> >> ----- Original Message ----- >> *From:* Eloise Pasteur <mailto:eloisepasteur@...> >> *To:* Maxxi Short <mailto:maxxi@...> >> *Cc:* secondlifescripters@... >> <mailto:secondlifescripters@...> >> *Sent:* Thursday, October 15, 2009 6:04 PM >> *Subject:* Re: Complex scripts and good style >> >> No, the compiled code has no comments, you're not being naive. >> >> And as someone else has commented, if I know I'm going to be >> storing a lot of stuff, I usually use additional scripts for >> memory scripts - those limits are still pretty tight for storing >> data in SL and not everyone wants to direct stuff to an outside >> server for a variety of reasons. >> >> El. >> >> On 15 Oct 2009, at 17:25, Maxxi Short wrote: >> >>> Many thanks for the responses, they've been really helpful! I >>> think my main script will be in the region of 500 lines which I >>> thought might be excessive, but Domchi says he has no problems >>> with 1,000 line scripts, so I think it would be more efficient to >>> have everything that logically belongs to the root in a single >>> script. >>> >>> I do comment quite heavily - I assume that "compilation" strips >>> out comments so 500 lines of code and 500 lines of comments would >>> be no different to 500 lines of code? Or am I being naive there? >>> >>> Maxxi. >>> >> >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Click here to unsubscribe or manage your list subscription: >> https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters >> > > _______________________________________________ > Click here to unsubscribe or manage your list subscription: > https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters _______________________________________________ Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
|
|
|
| Free embeddable forum powered by Nabble | Forum Help |