Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Syntax error with llGetListLength

Oliviero Ranimo
Registered User
Join date: 19 Jan 2009
Posts: 13
04-02-2009 06:36
Hi again.

Hopefully just a quick one. I'm being given a syntax error with the following line of code but cannot for the life of me see what is wrong. Supposedly the error is where the brackets begin surrounding mySounds.

integer listLength = llGetListLength(mySounds);

Here's the code in full to see if I'm going wrong elsewhere in the script.

list mySounds = ["FemHysteric1", "FemHysteric2", "FemHysteric3", "FemHysteric4", "FemHysteric5"];
integer listLength = llGetListLength(mySounds);
integer x;

default {
state_entry() {
llStopSound();

}

touch_start(integer num_detected) {
for (x = 0; x < listLength; x++)
{
llPlaySound((llList2String(mySounds, x), 1);
}
}

}

Thanks.
Ultralite Soleil
Registered User
Join date: 31 Aug 2006
Posts: 108
04-02-2009 07:10
You cannot make function calls outside of a function. Declare listLength globally but then assign it in state_entry, for example. You also have an extra open-paren in the llPlaySound line.
Oliviero Ranimo
Registered User
Join date: 19 Jan 2009
Posts: 13
04-02-2009 07:22
Thanks for that.

Now I've got another problem, not syntax related. What I'm trying to do is have the sound files played one after the other when the object is clicked. What seems to be happening at the moment is that the following sound almost immediately cuts off the one before. I'm guessing I need to involve a timer, or find a way to allow the sound file to play fully before moving on to the next. Any ideas as to what would be the easiest method for this?

Thanks again.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
04-02-2009 07:51
this may work
http://wiki.secondlife.com/wiki/LlSetSoundQueueing

list mySounds = ["FemHysteric1", "FemHysteric2", "FemHysteric3", "FemHysteric4", "FemHysteric5"];
integer listLength;
integer x;

default {
state_entry() {
listLength = llGetListLength(mySounds);
llStopSound();

}

touch_start(integer num_detected) {
llSetSoundQueueing(TRUE);
for (x = 0; x < listLength; x++)
{
llPlaySound((llList2String(mySounds, x), 1);
}
}

}
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Oliviero Ranimo
Registered User
Join date: 19 Jan 2009
Posts: 13
04-02-2009 07:59
That is very nearly there but unfortunately it'll only queue one sound. I don't know if there's any way to increase this by using some sort of workaround. I guess I'll keep plugging away at it. Thanks for your input, and if anyone else has any ideas i'd be glad to hear them.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
04-02-2009 08:16
ah ok, hmm, maybe put that call inside the for loop, so it does it before each sound, not sure though, i think the for loop might be too fast for it the sounds to catch up.

CODE

list mySounds = ["FemHysteric1", "FemHysteric2", "FemHysteric3", "FemHysteric4", "FemHysteric5"];
integer listLength;
integer x;

default {
state_entry() {
listLength = llGetListLength(mySounds);
llStopSound();

}

touch_start(integer num_detected) {
for (x = 0; x < listLength; x++)
{
llSetSoundQueueing(TRUE);
llPlaySound((llList2String(mySounds, x), 1);
}
}

}


you could possible try this one, adapted from the animation one i wrote a couple days ago
/54/1f/314508/1.html#post2376633


CODE

list mySounds = ["FemHysteric1", "FemHysteric2", "FemHysteric3", "FemHysteric4", "FemHysteric5"];
list times = [ 5.2, 8.1, 6.0, 5.2, 8.3];//times are just examples, change to what you need

integer i = 0;
integer len;

float time;

string sound;
string next;

default
{
state_entry()
{
len = llGetListLength(mySounds);
}

on_rez(integer rp)
{
llResetScript();
}

touch_start(integer num)
{
time = llList2Float(times, i);
sound = llList2String(mySounds, i);
next = llList2String(mySounds, (i +1) %len);
llSetTimerEvent(time);
llPlaySound(sound);
llPreloadSound(next);
}

timer()
{
i = (i +1) %len;
time = llList2Float(times, i);;
sound = llList2String(mySounds, i);
next = llList2String(mySounds, (i +1) %len);
llSetTimerEvent(time);
llPlaySound(sound);
llPreloadSound(next);
}

}
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Oliviero Ranimo
Registered User
Join date: 19 Jan 2009
Posts: 13
04-02-2009 08:25
OK I've cracked it. This is what I've gone with and it's working fine.

list mySounds = ["FemHysteric1", "FemHysteric2", "FemHysteric3", "FemHysteric4", "FemHysteric5"];
integer listLength;
integer x;

default {
state_entry() {
x = 0;
llStopSound();
listLength = llGetListLength(mySounds);
}

touch_start(integer num_detected) {
llSetTimerEvent(10.0);
}
timer() {

llPlaySound(llList2String(mySounds, x), 1);
x++;
state playing;
}


}

state playing {
touch_start(integer num_detected) {
llSetTimerEvent(0);
state default;
}
}
///

Only problem with this is that there is a wait of 10seconds before the first sound begins. I wasn't sure if setting the timer to 0 in the touch_star and then setting it to 10 in the actual timer event would work correctly. Although there's no reason I can't try it. I suppose we'll soon see. Thanks again!
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
04-02-2009 08:29
in the touch start you can set it to a very small amount of time, but bigger than 0.0, and then in the timer event change it to 10.0
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Oliviero Ranimo
Registered User
Join date: 19 Jan 2009
Posts: 13
04-02-2009 09:08
Yup! That works a treat. Here's the revised version.

list mySounds = ["FemHysteric1", "FemHysteric2", "FemHysteric3", "FemHysteric4", "FemHysteric5"];
integer listLength;
integer x;

default {
state_entry() {
x = 0;
llStopSound();
listLength = llGetListLength(mySounds);
}

touch_start(integer num_detected) {
llSetTimerEvent(1.0);
}


timer() {
llSetTimerEvent(10.0);
if (x < listLength){
llPlaySound(llList2String(mySounds, x), 1);
x++;
} else {
llSetTimerEvent(0);
llResetScript();
}
}

}

I added the if-else so that the script won't continue calling the timer event once it's reached the end of the list. Not sure if it's necessary to have both setTimer and Reset script. The reset script has to be there or once it's finished you can't start it again. Although now I think about it I could just set x to 0 again.

Thanks again.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
04-02-2009 09:23
if you use the increment method i used it should work
notice i put

i = (i+1)%len

/54/5a/274402/1.html#post2094873
/54/5a/274402/1.html#post2094889

list mySounds = ["FemHysteric1", "FemHysteric2", "FemHysteric3", "FemHysteric4", "FemHysteric5"];
integer listLength;
integer x;
integer OnOff = 0;

default {
state_entry() {
x = 0;
llStopSound();
listLength = llGetListLength(mySounds);
}

touch_start(integer num_detected) {
if(!OnOff){llSetTimerEvent(1.0);
OnOff = 1;}
else{llResetScript();}
}


timer() {
llSetTimerEvent(10.0);
llPlaySound(llList2String(mySounds, x), 1);
x = (x +1)%listLength;
}

}
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
04-02-2009 09:40
From: Ruthven Willenov
if you use the increment method i used it should work
notice i put

i = (i+1)%len

..........


I know this sounds like a really basic question, but I can't find documentation to explain what this operation means. Can you explain? :confused:
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
04-02-2009 10:06
i didn't understand it either, i just know it works for me lol.

edit: found this definition on this page http://www.answers.com/topic/modular-arithmetic

seems to fit this used, but i can't seem to understand how it works exactly. the remainder of 9/4 is 1, but so is 5/4, so 4 hours after 5 isn't 1, but 9, so i don't understand.

hmm, how about 5+4 = 9/7(12 - 5) remainder is 2? nope
5+4 = 9, 12/9 the remainder is 3, yeah, i'm all confused.

hewee! you told me about this, can you explain? lol

n.

A form of arithmetic dealing with integers in which all numbers having the same remainder when divided by a whole number are considered equivalent: Clocks use modular arithmetic with modulus 12, so 4 hours after 9 o'clock is 1 o'clock.
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
04-02-2009 10:31
From: Ruthven Willenov
i didn't understand it either, i just know it works for me lol.


Cool. I love black boxes. So tell me ..... on successive calls to this black box, what output does it produce? (I can't get in world right now to experiment, or I'd play with it myself to find out.)
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
04-02-2009 10:49
wait, i think i got it, the modular # is 12 with the clock example.

9+4 = 13
13/12 = 1 r1

so with a modular of 21
9+1= 10
21/10 = 2 r1 ?huh?

nope, still confused

edit: oh ok, further down, it shows that it re-wraps with the remainder once it reaches the modular, but what about for decreasing the number?

1 - 1 = 0
0 - 1 = -1
how does it know to start over at 12(or in this case 12 + -1 = 11)
because the result would be less than 0 it automatically goes to the modular?
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Ultralite Soleil
Registered User
Join date: 31 Aug 2006
Posts: 108
04-02-2009 11:00
A number mod 12 just gives results in the range 0 to 11.

0 % 12 = 0
1 % 12 = 1
2 % 12 = 2
...
10 % 12 = 10
11 % 12 = 11
12 % 12 = 0
13 % 12 = 1
14 % 12 = 2
...
etc.

So the code "x = (x + 1)%listLength" just forces the list index to be in the range 0 to (listLength - 1).

The long version of the same code is like this:
x = x + 1;
if (x >= listLength) x = 0;
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
04-02-2009 11:10
From: Ultralite Soleil
A number mod 12 just gives results in the range 0 to 11.

0 % 12 = 0
1 % 12 = 1
2 % 12 = 2
...
10 % 12 = 10
11 % 12 = 11
12 % 12 = 0
13 % 12 = 1
14 % 12 = 2
...
etc.

So the code "x = (x + 1)%listLength" just forces the list index to be in the range 0 to (listLength - 1).

The long version of the same code is like this:
x = x + 1;
if (x >= listLength) x = 0;


Ah! Now that makes sense, especially with your translation at the end. Thanks. :D
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
04-02-2009 11:21
that's what i meant (and thought, but wasn't sure if, that was the way it worked), just didn't know how to explain it lol, thanks ultralite
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
04-02-2009 14:05
%(modulus) is the same operation as r(remainder) from grade school when you first learned long division. it's the whole leftover after dividing one number into another.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
04-02-2009 14:28
From: Void Singer
%(modulus) is the same operation as r(remainder) from grade school when you first learned long division. it's the whole leftover after dividing one number into another.


Yeah. I just couldn't see at first how modulo was relevant here, so the notation was getting in my way. Got it now, though. Thanks for being patient.