Forums


How to fix a script so it does not die every sim restart?

Creating scripts

How to fix a script so it does not die every sim restart?

Postby Daniel Hoffman » Mon Nov 13, 2017 9:46 pm

Hi all! I am a non-scripter, to say the least. The most I can do is take a script and change variables. That being said, I found the below script on the always-useful Outworldz site. It is a script where you drop several sound files into a prim, along with the script, and the script then plays these files randomly with the incidence of them being played being a controllable parameter. (In other words, out of 4 sound files, the script will play one of them every x to y seconds.) I love it, it's fabulous and does just what I want... except...

...every sim restart (which is obviously all the time in Kitely), the script stops working and I have to manually find all my invisible prims with sounds and reset them. :( Does anybody know a line or two of code to add to this script so that it resets itself on a sim-restart?

Here's the script and humble thanks in advance if anyone can fix this:

// :CATEGORY:Sound
// :NAME:Sound_Prim_Script__Intermittent
// :AUTHOR:Anonymous
// :CREATED:2010-01-10 05:20:56.000
// :EDITED:2013-09-18 15:39:04
// :ID:810
// :NUM:1120
// :REV:1.0
// :WORLD:Second Life
// :DESCRIPTION:
// Sound Prim Script - Intermittent.lsl
// :CODE:


// Sound Prim Script - Intermittent
//
// Randomly picks a sound in inventory, plays it,
// waits a random interval, repeats.
//
// Set this between 0.0 and 1.0
float LOUDNESS = 0.5;
//
// Interval in seconds to be silent.
// If you set these to be less than 10 seconds,
// they default to 10 seconds.
integer SHORTEST = 60;
integer LONGEST = 180;
//
////////////////////////////////////////////////
default
{

state_entry()
{
if (SHORTEST < 10 ) SHORTEST = 10;
if (LONGEST < 10 ) LONGEST = 10;
if (SHORTEST > LONGEST) SHORTEST = LONGEST;

llSleep( 1.0 );
state noisy;
}

on_rez(integer start_param)
{
llSleep( 1.0 );
state noisy;
}

}
////////////////////////////////////////////////
state noisy
{

state_entry()
{
integer sounds = llGetInventoryNumber(INVENTORY_SOUND);

if ( sounds <= 0 ) state default;

string soundname = llGetInventoryName( INVENTORY_SOUND, llFloor(llFrand(sounds)) );
if ( soundname != "" )
{
llPlaySound( soundname, LOUDNESS );
}

state silent;
}

on_rez(integer start_param)
{
state default;
}

}
////////////////////////////////////////////////
state silent
{

state_entry()
{
llSleep( (float)(llFloor(llFrand(LONGEST - SHORTEST)) + SHORTEST) );
state noisy;
}

on_rez(integer start_param)
{
state default;
}

}

// END //
User avatar
Daniel Hoffman
 
Posts: 8
Joined: Tue May 07, 2013 7:27 pm
Has liked: 0 time
Been liked: 11 times

Re: How to fix a script so it does not die every sim restart

Postby Graham Mills » Tue Nov 14, 2017 9:12 pm

Not an expert but you need something along the lines of the following in the default state.
Code: Select all
    changed(integer c)
    {
        if (CHANGED_REGION_RESTART & c)
        {
            //code to run on restart
        }
    }
Graham Mills
 
Posts: 952
Joined: Sun Dec 23, 2012 2:26 pm
Has liked: 586 times
Been liked: 721 times

Re: How to fix a script so it does not die every sim restart

Postby Handy Low » Wed Nov 15, 2017 6:54 pm

I'm not inworld so I can't test it, but try this:

Code: Select all
// :CATEGORY:Sound
// :NAME:Sound_Prim_Script__Intermittent
// :AUTHOR:Anonymous
// :CREATED:2010-01-10 05:20:56.000
// :EDITED:2013-09-18 15:39:04
// :ID:810
// :NUM:1120
// :REV:1.0
// :WORLD:Second Life
// ESCRIPTION:
// Sound Prim Script - Intermittent.lsl
// :CODE:


// Sound Prim Script - Intermittent
//
// Randomly picks a sound in inventory, plays it,
// waits a random interval, repeats.
//
// Set this between 0.0 and 1.0
float LOUDNESS = 0.5;
//
// Interval in seconds to be silent.
// If you set these to be less than 10 seconds,
// they default to 10 seconds.
integer SHORTEST = 60;
integer LONGEST = 180;
//
////////////////////////////////////////////////
default
{

state_entry()
{
if (SHORTEST < 10 ) SHORTEST = 10;
if (LONGEST < 10 ) LONGEST = 10;
if (SHORTEST > LONGEST) SHORTEST = LONGEST;

llSleep( 1.0 );
state noisy;
}

on_rez(integer start_param)
{
llSleep( 1.0 );
state noisy;
}

}
////////////////////////////////////////////////
state noisy
{

state_entry()
{
llSetTimerEvent(0.0);
integer sounds = llGetInventoryNumber(INVENTORY_SOUND);

if ( sounds <= 0 ) state default;

string soundname = llGetInventoryName( INVENTORY_SOUND, llFloor(llFrand(sounds)) );
if ( soundname != "" )
{
llPlaySound( soundname, LOUDNESS );
}

state silent;
}

on_rez(integer start_param)
{
state default;
}

}
////////////////////////////////////////////////
state silent
{

state_entry()
{
llSetTimerEvent( (float)(llFloor(llFrand(LONGEST - SHORTEST)) + SHORTEST) );
}

timer()
{
state noisy;
}

on_rez(integer start_param)
{
state default;
}

}

// END /
Handy Low
User avatar
Handy Low
 
Posts: 231
Joined: Fri Nov 08, 2013 3:38 pm
Location: Yorkshire, England
Has liked: 206 times
Been liked: 140 times

Re: How to fix a script so it does not die every sim restart

Postby Daniel Hoffman » Thu Nov 16, 2017 8:23 pm

Thank you so much to you both! I will go in-world and test these out tomorrow, when I finally get to emerge from real-life into the more satisfying virtual life! :D

Daniel
User avatar
Daniel Hoffman
 
Posts: 8
Joined: Tue May 07, 2013 7:27 pm
Has liked: 0 time
Been liked: 11 times


Return to Scripting

Who is online

Users browsing this forum: No registered users and 2 guests