I had a problem with my site and it has been restored to 4th January. Sorry for any inconvenience.
Maintaining code can be a real pain in backside. Especially when you’re using shared code, almost always at a later date you will want to make the code more versatile to accommodate a scenario you hadn’t thought of before.
I’ve had experience this in an ASP / VbScript environment, and therefore I’m going to use the terminology of page and functions as opposed to files and classes:
- Rework the code and update all pages. This is obviously a bad idea.
- To extend inflexible code: Rename the function and create a wrapper in its place to access the function using default parameters that are compatible with your existing codebase.
- Create functions that are extendable.
To use optional parameters, pass them in an Array or dictionary object. This way you can add additional ones. The benefit that Arrays have over Dictionary objects is that they use less resources. This can be important if you are developing for a popular website.
Another advantage of using Arrays is that you’ll use less code calling the function. Using a dictionary object you’ll have to add each parameter separately, then pass the dictionary object as the parameter of the function.
On the other hand, code will be more legible using dictionary objects. Dictionary objects use key value pairs to tell you that key A has a value B. You’ll not have to bother about the order of parameters, but you’ll have to know the keys of each function. It results in verbose, legible, resource intensive code.
It’s good practice to make code easy to maintain, so sometimes you’ll want to use less code using recursive functions. In order to find out how to this works in Second Life I created this small recusive example:
integer i = 0;
integer top = 0;
if (i <= top)
llSay(0, "Hello, Avatar!");
i = 0;
top = Monkeys();
This script says monkeys an increasing amount of times every time you touch it by calling itself if and keeping track of the total amount of times the function is called. First time there will be 1 monkey, next time 2 monkeys etc. Find more products at our shop in Badmoon.
I had to create a simple script to turn a neon sign on and off. I decided to have both versions of the sign in a single texture and changing the offset with a script. Instead of using a timer and using llSetTimeout() instead I opted to pause the script for a small amount of time. The script does not respond when it’s sleeping which should be less laggy then the timeout. All i do then at the start of a state is offsetting the texture to show the on/off alternatively.
Hope this is of use to you. See the result in our Higher / Lower game at Badmoon.
I’m still working on the looks of the site. If you’re using Opera, you might have noticed the horizontal scrollbar. It will be gone soon! But in the meantime, press ctrl-F11 and it will be gone.
There are some positioning issues too but I’m working on this in my spare time, so watch this space.