Misc Advanced LSL Tips

By Xah Lee. Date:
Get your Xah Particle Maker today!

Problem With llSleep and Queue'd Listen Commands

When scripting, llSleep can be used to set a period of delay. For example, suppose you are scripting a grenade launcher, which has a reload time. That is, after you shoot out a grenade, you want the gun to not be able to shoot another, until a period of time has passed, typically 5 seconds. This is to prevent the weapon from firing grenades like a machine gun, which would be unrealistic and the weapon would be ban'd.

However, if your trigger for the grenade launch is based on chat commands (listen), then llSleep is not a good option. Because, users may pull the trigger many times, by a hotkey from a gesture that speaks the command, then when your script goes to sleep, the command will be queue'd up. So when the script wakes, it immediately launches another grenade. User many have pressed the hotkey many times before, and realized there's a reload time and forgot about it, but all of a sudden, another grenade is launched unexpectedly. This is not desirable.

The solution is to use a timer instead. For example, here's a snippet that uses llSleep:

llPlaySound(reloadDoneSndName, 1);
llOwnerSay("Ready to fire.");

The code should be changed to like this:

llListenControl(listenControlHandle, FALSE);
llSetTimerEvent(reloadTime); // start a timer event

    llListenControl(listenControlHandle, TRUE);
    llSetTimerEvent(0); // quit timer evet
    llPlaySound(reloadDoneSndName, 1);
    llOwnerSay("Ready to fire.");

A scripting friend Matthias Rozensztok has a combat hud system. “brave new world combat system”. Pretty nice. http://bnwcs.org/.

Some tips from sl damage weapon maker Matthias Rozensztok:

Rumor has it that this bug is fixed and about to roll out: http://jira.secondlife.com/browse/SVC-3895. Basically, any script that does rez, lags the sim. This is especially important in combat sims, where there are 20 or more people all firing guns, and each gun rez like 10 bullets per second. Though, i haven't personally verified this bug. I heard some rumors that when you write a gun, you want to not use mono.

Second Life: How to Give Out Things Full Perm But Not Script.

Learned today that the Linden Scripting Language was designed by Cory Ondrejka. Sources: “Cory Ondrejka's departure in his own words” (2007-12-11), by Tateru Nino. Source.

Cory Ondrejka has his blog at http://ondrejka.net/.

A interview about open sourcing the Second Life viewer code. “Interview with Second Life's Cory Ondrejka” (2007-01-17), written by Glyn Moody. Source

Want to dash through walls?
Try Xah Tele-Dasher!