Jump to content

Using a variable in llPlaySound


Sarah Glenelg
 Share

You are about to reply to a thread that has been inactive for 1723 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi there - I have a very simple issue that is foxing me.  I have an object with some sound files in it - named SND01, SND02, SND03, etc.

llPlaySound("SND01", 1.0)  works fine.  But if I have string  sound="SND"+ soundnum (where say string soundnum="01") and then do llPlaySound(sound,1.0) I get a debug message saying "Could not find sound 'SND01'" even though SND01 is in the inventory of the object.  Is it simply the case that one cannot use string variables in llPlaySound for the sound file name?

Thanks

Link to comment
Share on other sites

Thank you for your suggestions.  So I went to a sandbox and created simple prim with two sound files in it - SND07 and SND08.  The simple script below worked fine:

string soundnum;
string sound;

default
{
   touch_start(integer total_number)
    {
   
   soundnum = "07";
   sound = "SND"+soundnum;
   llSay(0, sound);
   llPlaySound(sound, 1.0);
   } 

But this slightly more complex script failed with debug error msg "Could not find sound 'SND07 '."

string soundnum;
string sound;
string body = "CTRL SND07 This is the sound of a dog barking";

default
{
   touch_start(integer total_number)
    {
   
    if (llSubStringIndex(body,"CTRL SND") != -1)
           {
          integer numIndex = llSubStringIndex(body, "SND");
          string soundnum = llGetSubString(body, numIndex+3, numIndex+5);
          string sound= "SND"+soundnum;
          llSay(0,sound);
          
         llPlaySound(sound,1.0);
       }  
  }

}

 llSay(0,sound) shows 'SND07' in both cases.

So it seems the issue is somehow connected to how I extract 'SND07' from the string 'body'.

 

Link to comment
Share on other sites

31 minutes ago, Sarah Glenelg said:

So it seems the issue is somehow connected to how I extract 'SND07' from the string 'body'.

I think so too.

llGetSubString returns a string inclusive of the specified start and end positions.

default
{
    state_entry()
    {
        llOwnerSay(
          llGetSubString("0123456789", 3, 5)
            );
    }
}

says "345" for example.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1723 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...