Scripting change: show the "too many events" error

Creating scripts
Post Reply
User avatar
Oren Hurvitz
Posts: 361
Joined: Sun Dec 23, 2012 8:42 am
Has thanked: 19 times
Been thanked: 499 times
Contact:

Scripting change: show the "too many events" error

Post by Oren Hurvitz »

We have updated the system today with a small change to the scripting system: there's a scripting error that previously was hidden, and now it will be shown on-screen. That error is "too many events". This error happens when a script generates over 1,000 events, but it can't handle them because it's busy doing something else.

This error is rare: in all of Kitely, there are only a few scripts that cause it. So if you see this error on-screen then know that you are special :D

Here's an example of one script where this happens: a door-opening script that's used in Kitely Welcome Center, among other places. When you touch a door that contains this script, the door swings open (or closes, if it was already open). The problem is that the door animates the opening and closing by changing the prim's rotation by tiny increments, for the duration of 1 second. Every time the prim's rotation changes, the script is supposed to get an event. But because the script is busy in the animation loop it can't receive the event, so XEngine saves the event, intending to send it to the script later. Once over 1,000 events have been saved like this, you will start seeing the error "too many events".

I have fixed this particular script so that the error doesn't appear in Kitely Welcome Center anymore. The way that I've fixed it may be useful to other scripters who encounter this error, so here's how I did it: I limited how smooth the animation is. The script originally tried to generate as many rotation increments as possible over 1 second. This created over 100,000 rotation increments! This is extremely wasteful since no one has a computer that can render 100,000 frames per second. So I made the script generate exactly 100 rotation increments instead. Since the rotation takes place over 1 second, this means that the smoothness is 100 fps, which is still plenty!

This was the original animation code (it generates as many rotation increments as possible):

Code: Select all

    llResetTime();
    while (llGetTime() < SECONDS_TO_ROTATE) {
        float time = llGetTime();
        if (! gClosed)
            /*
             * Invert the timer for closing direction
             */
            time = SECONDS_TO_ROTATE - time;
 
        rotation rotationThisStep = llEuler2Rot(gRotationPerSecond * time) * gRotationClosed;
        vector positionThisStep = hingePosition - HINGE_POSITION * rotationThisStep;
        llSetLinkPrimitiveParamsFast(linkNumber, [PRIM_ROT_LOCAL, rotationThisStep, PRIM_POS_LOCAL, positionThisStep]);
    }
And this is the new code (it generates 100 rotation increments, or "animation steps"):

Code: Select all

    float ANIMATION_STEPS = 100;
    llResetTime();
    float lastUpdateTime = 0.0;
    while (llGetTime() < SECONDS_TO_ROTATE) {
        float time = llGetTime();
        if (time - lastUpdateTime >= SECONDS_TO_ROTATE/ANIMATION_STEPS) {
            lastUpdateTime = time;
    
            if (! gClosed)
                /*
                 * Invert the timer for closing direction
                 */
                time = SECONDS_TO_ROTATE - time;
     
            rotation rotationThisStep = llEuler2Rot(gRotationPerSecond * time) * gRotationClosed;
            vector positionThisStep = hingePosition - HINGE_POSITION * rotationThisStep;
            llSetLinkPrimitiveParamsFast(linkNumber, [PRIM_ROT_LOCAL, rotationThisStep, PRIM_POS_LOCAL, positionThisStep]);
        }
    }
It's desirable to fix this error (rather than hide it) because this error is an indication that the script isn't working as well as it can. For example, in this door-opening script, the animation loop used to cause high CPU, so the animation wasn't smooth because XEngine was working so hard.
These users thanked the author Oren Hurvitz for the post (total 11):
Graham MillsIlan TochnerIain McCrackenAda RadiusKrull KittyChris NamasteChristine NynSnoots DwagonJohn MelaMike Lorrey and one more user
User avatar
Krull Kitty
Posts: 100
Joined: Thu Aug 06, 2020 1:25 pm
Has thanked: 39 times
Been thanked: 81 times

Re: Scripting change: show the "too many events" error

Post by Krull Kitty »

Oh my! Is that a challenge Oren?

Thinking about all the functions I can possibly cram into multiple states through a cycling loop that continuously
counts the prims on the sim as it shouts out the number to every possible key it finds as well as internal linked messages
while performing complex math and calculates figuring out all of the angles between each prim in radians while
building multiple lists and saving those lists to a notecard while trying to remotescriptpin every prim key and avatar found,
while converting the rotations and angles list into quaternions and also saving those in a list only to later dump it into a
notecard while calculating Pi in a timer event and trying to prove the existence of dark energy and solving the
string theory problem and.... And.... And....

Getting light headed just thinking about it. :shock:
These users thanked the author Krull Kitty for the post:
Snoots Dwagon
User avatar
Baschar Gibran
Posts: 10
Joined: Sat Dec 19, 2020 12:40 pm
Has thanked: 4 times
Been thanked: 2 times

Re: Scripting change: show the "too many events" error

Post by Baschar Gibran »

hm, my door close now all to the wrong site ....
User avatar
Snoots Dwagon
Posts: 422
Joined: Mon Jul 30, 2018 9:45 pm
Has thanked: 442 times
Been thanked: 779 times

Re: Scripting change: show the "too many events" error

Post by Snoots Dwagon »

HOW TO BUILD A DOOR-- the Dwagon way
http://elfclan.spruz.com/pt/Making-a-D ... s/blog.htm
These users thanked the author Snoots Dwagon for the post (total 4):
Zyzzyx QinanAlexina ProctorKrull KittyDee Ferry 2
~~~~~~~
I'm a dwagon in real life too. (Ask my sister, who totally agrees.)

~~~~~~~
User avatar
Krull Kitty
Posts: 100
Joined: Thu Aug 06, 2020 1:25 pm
Has thanked: 39 times
Been thanked: 81 times

Re: Scripting change: show the "too many events" error

Post by Krull Kitty »

Imagine putting a door script into the door hinge only to discover later
that the hinge is actually connected to the house itself :shock: :?

The entire house swings open leaving the door behind ROFL. XD
User avatar
Mike Lorrey
Posts: 361
Joined: Sun Sep 04, 2016 5:40 pm
Has thanked: 71 times
Been thanked: 269 times

Re: Scripting change: show the "too many events" error

Post by Mike Lorrey »

Thanks for this script btw, with the fixes. One thing that annoys me about the llSetPrimitiveParams family of functions, is they never included a RATE parameter so you could control the speed that a parameter changed from one to the other, so the system would automatically interpolate through the range of values between the old and new ones. While the Fast versions of these functions are welcome, they could have just added a rate parameter to the original functions so you could do it fast, slow, at whatever speed you wanted. Of course the OS devs are obstinately not liking this idea either.
These users thanked the author Mike Lorrey for the post (total 2):
Tess JuelChristine Nyn
Post Reply