An Interesting LSL Programming Problem
One of the tough parts of learning Linden Scripting Language is knowing where to start - and as someone who has taught programming, I always advocate starting with a problem to solve. Murrough McConachie recently posted a problem to the SL Scripters list (subscription available through this link). It is interesting because it deals with listening events and Second Life geography limitations for scripts while dealing with a project that is very visual in nature.
From the SL Scripters email list, posted with permission from Murrough McConachie:
I own an Island and I operate it in 'Midnight' mode, which therefore makes use of local lighting (objects/prims that you can set as a light). I can change colours, intensity, switch lights on, off etc.
Obviously I have a lot of lights and each light is using s 'listen' event to wait for instructions. I started gettting a few hundred lights and I need lots more. It all started getting a bit messy and I could not remember which lights were in which groups, which channel they communicated on etc etc. This would start to degrade performance, so I have decided to look for another way, say to achive the best performance I can whilst excepting what I require.
SL's restrictions, allow objects to communicate 100M using listen events, and about 24'ish using link messages (that are more efficient and less laggy or resource hungry). In addition , an Island is 256m by 256m
Faced with this, my approach is to divide the island into 4 quadrants and at the geo-centres of each provide 4 quad transmitters/listeners. Then I was to divide the island into 16m by 16m squares and in each, place a listener/transmitter. Then any light needed would be 'linked' to its nearest listen/transmitter.
In total there would be 4 quad transmitters and 256 listeners. SInce I can filter the listeners to listen only to their quad and nothing else, i can minimise lag. This would provide me with a communication system.
Finally then a protocol in the form of a lighting script, which would enable me to group lights together, set individual colours turn on turn off. This im still thinking about as I might want to turn on/off a group of lights over the whole island, or limit it to a particular section.
Once done, then I can create any object, put the generic lighting script in it (set the object name and description to its 'address' and group etc. and the system takes over.
to Control I would just shout the command on a channel, it would be picked up by the nearest quad, routed back and delivered to the local light. A final central transmitter could be for automatic or timed control.
So in total upto a maximim of 261 listen events (depending if I enable every 16 by 16m square , all heavily filtered and I will have total lighting control across the island. This is just started to be scripted. My island is Elation Island if you want to see it develop and view the scripts as I create.
The discussion so far has been interesting, and has included some really good thoughts on solutions. If you're new to Linden Scripting Language and are interested in what this is all about, consider joining the list and/or trying to solve the problem itself within the constraints of Second Life. You can also visit the Linden Scripting Language Portal for some references.
Technorati Tags:
Delicious
Digg
Technorati
Thank you
Thanks Fugazzi, because of this article I have joined the Scripting group you alluded to. I am an established Java programmer along with other languages but I am in the process of learning LSL.
I agree with you that the best way to learn a language is to solve a problem. Currently I am trying to solve the problem of easily teleporting between SIMS. I know that there are a lot of products out there to do that, I think I have bought several of them, but I am looking for something a little more asthetic(?) Anyway, I enjoy your articles and the links. Very informative!
llRegionSay
well he could use llRegionSay, to overcome the 100m limit.
http://wiki.secondlife.com/wiki/LlRegionSay
llRegionSay is the answer
llRegionSay is the answer, as obi-wan pointed out. This previously was a super interesting LSL scripting problem. The type of silliness that developers needed used to need to implement the types of thing suggested here are now obsolete. More's the pity, in a way, because it lead to fun and interesting things, like little communication blimps...