Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Global Variable not computing in Timer() Event!?!

Nyef Nyak
Junior Member
Join date: 23 Jul 2004
Posts: 17
08-10-2004 20:15
First off, I'm leaving all my newbie comments in for the people who would like to learn from this like me, so...

This is what I have: a list that I wanna call every entry from, with a delay of a couple seconds. I've tried llSleep but need to be able to stop it when I need to, so it wont work, so this is what I have that I think SHOULD be working!

-----------------BEGIN CODE----------------------
string callingnumvar;
default
{

///////Skipping to problem code for the post

state_entry() //When entering state...
{
llListen( 0, "", llGetOwner(), "" ); //Listen for owner to say something on channel 0
randomizednums = llListRandomize(basenums, 1); //randomize base numbers into that list
for (i = m ; i<75;i++) //start with index of m and go down to the next num each time
{
callingnumvar = llList2String(randomizednums,i); //set the string to be said to the next index in the list
llSetTimerEvent(3.0);
}
}

timer()
{
llSay(0, callingnumvar);
llSay(0, "debug";);
}

-----------------END CODE-------------------
and what I end up with it saying is
Object:
Object: debug
Object:
Object: debug
Object:
Object: debug
-and so on
now it works fine without the timer and with the llSay(0, callingnumvar); put up in the for statement. can anyone tell me why this isnt working and a better way to do it? Thanks in advance!
Pete Fats
Geek
Join date: 18 Apr 2003
Posts: 648
08-10-2004 20:34
Just guessing here (as your above post is missing a ton a defines..), but you are basically just overwriting the old string with a new value. If you want the string to append the new value, rather then replace, try this:

callingnumvar += llList2String(randomizednums,i);
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
08-10-2004 20:35
Compilation error(s):
"basenums" variable not defined within scope.

"list llSetTimerEvent(" trying to compile a variable with name == a keyword. (you have "list" alone by itself on the line before llSetTimerEvent.)

Also, please surround your code with [CODE ] and [/CODE ] (Remove the spaces)

==Chris

EDIT: Sorry about sounding so anal, I just read and mentally interpret code better this way :)
Alondria LeFay
Registered User
Join date: 2 May 2003
Posts: 725
08-10-2004 20:37
Well, to start with, I don't think your loop is doing what you want it to do. I assume you want it to say each occurence of callnumvar opposed to just the last one. As written, each for loop resets the timer to trigger for 3 seconds, and since the loop should take less than three seconds, the timer() event will never fire until the loop is completed. This should probably do what you need (** Disclamer: Not tested, sleep deprived, over-worked, code)

CODE

// make basenums a global but recycle it to store
// random numbers list also.
list basenums = [...];
// i was set to m in the original code... not sure where m
// came from...
integer i;
default
{
state_entry()
{
llListen( 0, "", llGetOwner(), "" );
// Randomize the list
basenums = llListRandomize(basenums, 1);
// Start the timer
llSetTimerEvent(3.0);
}
timer()
{
// Say element i from basenums
llSay(0,llList2String(basenums,i);
i = i + 1;
// Stop timer if i went through it's maximum loops
if (i > 74)
{
llSetTimerEvent(0.0);
}
}
}
Nyef Nyak
Junior Member
Join date: 23 Jul 2004
Posts: 17
08-11-2004 02:54
sorry guys, just didnt wanna give up the whole code, which is too long to post really. but I have everything defined. I just wanted each value in the list said once.

Alondria's code worked with some modifications to fit the rest of the script, thanks alot all. :)

It's really hard going from vb to LSL...