Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llsay based on sound played

Nectere Niven
Gadget Junky
Join date: 12 Jan 2007
Posts: 211
08-01-2007 20:20
Before I drive myself batty:

I have a sound script I am playing with that might play any number of sounds in its inventory, I am wondering if its even possible to put an if statement in the common sound script that reads something like the following or am I going about it wrong - OR is it not possible (partial script to save space, its a fairly common one):

CODE

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

if ( sounds <= 0 ) state default;

string soundname = llGetInventoryName( INVENTORY_SOUND, llFloor(llFrand(sounds)) );
if ( soundname == "Sneeze male" )
{
llPlaySound( soundname, LOUDNESS );
llSay("Excuse Me");
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
08-01-2007 20:30
Seems reasonable to me. The code you posted wiill only play the sound if it matches the name you are looking for, is this the problem you are having? If so, you can put the llPlaySound() outside the name check:

CODE

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

if ( sounds <= 0 ) state default;

string soundname = llGetInventoryName( INVENTORY_SOUND, llFloor(llFrand(sounds)) );

llPlaySound( soundname, LOUDNESS );

if ( soundname == "Sneeze male" )
llSay("Excuse Me");
Nectere Niven
Gadget Junky
Join date: 12 Jan 2007
Posts: 211
08-01-2007 20:44
Actually the problem I am having is a syntax error when it hits the next line

state silent;

So I thought either I had the wrong idea about how to do it, or it wasnt possible.
The general idea is the inventory will hold a set of sounds, to which I will have a llsay for each sound randomly picked by frand (there are only about 5 or 6 sounds I plan to use) when chosen such as playsound Sneeze/say Excuse me etc, so far I am just trying to get a compile :P

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 = 30;
integer LONGEST = 60;
//
////////////////////////////////////////////////
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)) );

llPlaySound( soundname, LOUDNESS );

if ( soundname == "Sneeze male" )
llSay("Excuse Me");
}
}

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;
}

}
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
08-02-2007 02:53
From: Nectere Niven
Actually the problem I am having is a syntax error when it hits the next line

state silent;
Looks like stray bit of code got repeated. Might remove the lines:
From: someone

state silent;
}

on_rez(integer start_param)
{
state default;
}

}
that immediately precede
From: someone

////////////////////////////////////////////////
state silent
{
...
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
08-02-2007 12:30
Looks to me like you have two extra brackets above "state silent;"
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
08-02-2007 16:01
From: Boss Spectre
Looks to me like you have two extra brackets above "state silent;"
:o Oh, yeah. That would make the braces match with the additional merit of actually making sense. :o