Sarah Glenelg Posted August 7, 2019 Share Posted August 7, 2019 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 More sharing options...
Qie Niangao Posted August 8, 2019 Share Posted August 8, 2019 Sounds good to me. (heh) My suggestion: Go to a sandbox, rez a fresh prim, drop in the sound asset, and write the simplest possible script to do this, and see what it does. If it doesn't work, can we see that script? Link to comment Share on other sites More sharing options...
Mollymews Posted August 8, 2019 Share Posted August 8, 2019 1 hour ago, Sarah Glenelg said: I have string sound="SND"+ soundnum (where say string soundnum="01") might be best to check that this is actually so with a llSay(0, sound) Link to comment Share on other sites More sharing options...
Sarah Glenelg Posted August 8, 2019 Author Share Posted August 8, 2019 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 More sharing options...
Qie Niangao Posted August 8, 2019 Share Posted August 8, 2019 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. 1 1 Link to comment Share on other sites More sharing options...
Sarah Glenelg Posted August 8, 2019 Author Share Posted August 8, 2019 I got it - my string extraction was including a space so the script was looking for "SND07 " rather than "SND07". Just didn't notice the extra space in the debug message. Thanks Qie for solving this newbie error. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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