Weebit Offcourse

Nudge gently.

Archive for September 2014

multiple listeners and rigging a script

leave a comment »

Found another problem with the TouchMeObject script (wrote about it in last post). New, improved version is posted (same URL). The problem was of my own making, a result of trying to avoid having multiple listeners created. I hope this update finds anyone that might have used the earlier version.

A listener creates a significant load in a simulator, enough to warrant caution in their creation. So, it is best practice to avoid having static (persistent) listeners in a simulator if users are not interacting with the object.

In preparing the TouchMeObject, I hastily threw in a “BUSY” variable (BOOLEAN) to clamp down listener creation while the object attended to a user (make second, third users wait ’til first user is done). But, I FAILED to provide any response to the next user to touch the object.

(This could be tested by two users, or one user with an alt. Touch object with first avatar, then touch with second user before the first responds to their Dialog prompt. The object does not respond.)

The problem in the first TouchMeObject script is obvious now, one I should have noticed; had just never gone the “BUSY” route before. My old, lazy approach has typically been to create a listener, wait for X seconds of inactivity, and then remove the listener.

Not having looked at this “concurrency” issue in a while, at least as it relates to use of the llDialog function, I had a look around. Seems that how best to deal with multiple listeners is still a matter of discussion…and by much more advanced scripters*.

Still, the digging paid off: I noticed that the SL Wiki page for the llListen function states:

“…handles are assigned sequentially starting at 1”

Light bulb attachment flickers, and an old lazy approach is upgraded to a newer lazy approach. Now, we’ll create a listener only if we have ZERO stored as the EARS_OPEN handle (integer variable, now acting as BOOLEAN). (Just have to remember to set it to ZERO everywhere that counts.)

But wait! What if a user touches the object and gets the dialog prompt, then gets distracted by cute kitty pictures in a browser, and returns to the dialog prompt in (X + 1) seconds?

Answer: No joy.

It aint elegant. It’s not even satisfying; and, it has its problems. But…

It’s something I can live with.

*UPDATE* (added single line to clear any float text if not assigned)

state_entry()
{

//WAS FLOATING TEXT ASSIGNED ABOVE?
if (DISPLAY_FLOATING_TEXT) llSetText( llGetObjectName(), FLOAT_TEXT_COLOR, 1.0 );
else llSetText( “”, FLOAT_TEXT_COLOR, 1.0 );
//SEE WHAT’S BEEN ADDED TO CONTENTS
checkInventory();

}

* To read some of the various issues related to the use of listeners, see:

Written by azwaldo

September 12, 2014 at 10:34 pm

new script for new scripters

leave a comment »

First CC-licensed script is now completed for the 2014 OpenSimulator Community Conference. This is part of an activity that finds more collaboration in two days than most previous projects saw…ever!

Yes!

The TouchMeObject script is meant to ease the set-up of a simple “giver” object. Add to a sign or poster or kiosk, whatever…then drag items from Inventory that are to be delivered when user touches the object. Script detects that change and commits those items as gifts. Several behaviors are managed just by editing variables.

Instructions at each step.

image showing text that is a sample of code described here
TouchMeObject script (click image to open page with full script)

Take it for a spin if you’d like, see if it works…holler with any feedback. Please distribute willy-nilly.

I wonder: Do folks still write example scripts like this…commented to the teeth to help new scripters sort things out? (Especially in OpenSim where users seem to know what they’re doing.)

In any case, it was a useful exercise as it forced a couple of decisions that might not have come up, otherwise.

Written by azwaldo

September 12, 2014 at 11:07 am