Skip to main content

Senior Web Engineer. Open web / music. Remote DJ. Tall Dutch guy. #3million

micro.blog/sander

svandragt

mixcloud.com/cloudseer

 

Site updates

I had a problem with my site and it has been restored to 4th January. Sorry for any inconvenience.

 

Passing and receiving multiple values to VbScript functions

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:

  1. Rework the code and update all pages. This is obviously a bad idea.
  2. 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.
  3. 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.

 

LSL tests: recursive function

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;
integer Monkeys()
{
    llOwnerSay("monkeys");
    i++;
    if (i <= top)
        return Monkeys();
    else
        return i;
}
default
{
    state_entry()
    {
        llSay(0, "Hello, Avatar!");
    }
    touch_start(integer total_number)
    {
        i = 0;
        top = Monkeys();
        llOwnerSay((string)top);
    }
}

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.

 

LSL tests: walking states

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.

default
{
    state_entry()
    {
        llOffsetTexture(0.0,0.25,ALL_SIDES);
        llSleep(1.37);
        state off;
    }
}

state off
{
    state_entry()
    {
        llOffsetTexture(0.0,0.75,ALL_SIDES);
        llSleep(.723);
        state default;
    }
}

Hope this is of use to you. See the result in our Higher / Lower game at Badmoon.

 

Site comments

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.