Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Storing a value during a listen event

Cherry Hotaling
Registered User
Join date: 25 Feb 2007
Posts: 86
08-04-2007 22:18
Hello,

I was wondering what im doing wrong here.

I wanted the variable to store based on which number I said 0, 1, 2 (This could be apples, pears, Bananas But I chose 0 1 2)

Its listening on channel 2 but it seems no matter how much I say /2 1 or /2 2 it allways says to me that its 0

Anyone have any ideas?

Thanks for your time,
-Cherry Hotaling

integer Channel = 2; // Arbitary Channel

integer number = 0;

default
{
state_entry()
{
llListen(Channel,"",llGetOwner(),"";);
}


listen(integer channel, string name, key id, string message)
{


if ( message == "0" )
{
integer number = 0;
}

if ( message == "1" )
{
integer number = 1;
}

if ( message == "2" )
{
integer number = 2;
}




if (number == 0)
{
llSay(0, "I am 0 Right now";);
}

if (number == 1)
{
llSay(1, "I am 1 Right now";);
}

if (number == 2)
{
llSay(0, "I am 2 Right now";);
}


}

}
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
08-04-2007 22:47
From: Cherry Hotaling
Its listening on channel 2 but it seems no matter how much I say /2 1 or /2 2 it allways says to me that its 0
You declared a global integer named "number" and assigned it a value of 0. Then, in each of your if clauses, you declare *new* integers named "number" and assign them values, which are immediately lost because those new integer variables go out of scope. The value of your global "number" variable is never changed. Drop the "integer" tags in each of your if clauses, and it should do what you want.
Johnii Nowhere
Registered User
Join date: 20 Aug 2006
Posts: 6
scope issue
08-04-2007 22:49
You need to take out the "integer"definitions lower in the code.. you defined "integer number" as a global. (which is good)... but then you redefined a variable called number again within the events. If you take out the integer definitions outside the global area... all will work off the global definition of "number"

Can't tell you how many times I catch myself doing this.

Johnii
Cherry Hotaling
Registered User
Join date: 25 Feb 2007
Posts: 86
08-05-2007 01:55
Oh thank you so much that did the trick.

ended up with:

integer Channel = 2; // Arbitary Channel

integer number = 0;


default
{
state_entry()
{
llListen(Channel,"",llGetOwner(),"";);
}


listen(integer channel, string name, key id, string message)
{


if ( message == "0" )
{
number = 0;
}

if ( message == "1" )
{
number = 1;
}

if ( message == "2" )
{
number = 2;
}




if (number == 0)
{
llSay(0, "I am 0 Right now";);
}

if (number == 1)
{
llSay(1, "I am 1 Right now";);
}

if (number == 2)
{
llSay(0, "I am 2 Right now";);
}


}

}



Again thank you