Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

~Why won't this script listen to me?~

Shippou Oud
The Fox Within
Join date: 11 Jul 2005
Posts: 141
04-17-2007 10:10
I'm having problems with this. Everything looks like it's right, but from experance I know it's probly something simple that is causing the keywork not to fire on comand.
From: someone

integer chan;
integer chano = 30;
integer tim;
list time = ["5m","4m","3m","2m","1m","30s"];
default
{

state_entry()
{
tim = 120;
chan = (integer) llFrand(999999) + 1;
llListen(chano,"",llGetOwner(),"";);
}
listen(integer chano, string name, key id, string choice )
{
if (choice == "time";)
{
llListen(chan,"",NULL_KEY,"";);
llDialog(llGetOwner(), "Please select a time.", time,chan);
}
}
listen(integer chan, string name, key id, string choice1 )
{
if (choice1 == "5m";)
{
tim = 300;
llSetTimerEvent(tim);
llListenRemove(llListen(chan,"",NULL_KEY,"";));
}
if (choice1 == "4m";)
{
tim = 240;
llSetTimerEvent(tim);
llListenRemove(llListen(chan,"",NULL_KEY,"";));
}
if (choice1 == "3m";)
{
tim = 180;
llSetTimerEvent(tim);
llListenRemove(llListen(chan,"",NULL_KEY,"";));
}
if (choice1 == "2m";)
{
tim = 120;
llSetTimerEvent(tim);
llListenRemove(llListen(chan,"",NULL_KEY,"";));
}
if (choice1 == "1m";)
{
tim = 60;
llSetTimerEvent(tim);
llListenRemove(llListen(chan,"",NULL_KEY,"";));
}
if (choice1 == "30s";)
{
tim = 30;
llSetTimerEvent(tim);
llListenRemove(llListen(chan,"",NULL_KEY,"";));
}
}

timer()
{
llTriggerSound ("",1);
llRezObject("Ballt", llGetPos()+<0,0,2>, <0,0,0>, llGetRot()+<0,0,0,0>, 0);
}
}
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
04-17-2007 10:23
You've got two listen event handlers. IIRC, it'll only see the last one that you have - any previous ones will be ignored.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Destiny Niles
Registered User
Join date: 23 Aug 2006
Posts: 949
04-17-2007 11:00
REVISED SCRIPT
using state and else if

CODE

integer chan;
integer chano = 30;
integer tim;
list time = ["5m","4m","3m","2m","1m","30s"];
default
{

state_entry()
{
tim = 120;
chan = (integer) llFrand(999999) + 1;
llListen(chano,"",llGetOwner(),"");
}
listen(integer chan1, string name, key id, string choice )
{
if (chan1 == chano) // filter for chano only
{
if (choice == "time")
{
state asktime; //change state to asktime
}
}
}
}
state asktime
{
state_entry()
{
llListen(chan,"",NULL_KEY,"");
llDialog(llGetOwner(), "Please select a time.", time,chan);
}

listen(integer chan1, string name, key id, string choice1 )
{
if (choice1 == "5m")
{
tim = 300;
llSetTimerEvent(tim);
llListenRemove(llListen(chan,"",NULL_KEY,""));
}
else if (choice1 == "4m") //else if is your friend
{
tim = 240;
llSetTimerEvent(tim);
llListenRemove(llListen(chan,"",NULL_KEY,""));
}
else if (choice1 == "3m")
{
tim = 180;
llSetTimerEvent(tim);
llListenRemove(llListen(chan,"",NULL_KEY,""));
}
else if (choice1 == "2m")
{
tim = 120;
llSetTimerEvent(tim);
llListenRemove(llListen(chan,"",NULL_KEY,""));
}
else if (choice1 == "1m")
{
tim = 60;
llSetTimerEvent(tim);
llListenRemove(llListen(chan,"",NULL_KEY,""));
}
else if (choice1 == "30s")
{
tim = 30;
llSetTimerEvent(tim);
llListenRemove(llListen(chan,"",NULL_KEY,""));
}
}

timer()
{
llTriggerSound ("",1);
llRezObject("Ballt", llGetPos()+<0,0,2>, <0,0,0>, llGetRot()+<0,0,0,0>, 0);
state default; //return to default state
}
}


Use SYS SLADE version. It's better.
Sys Slade
Registered User
Join date: 15 Feb 2007
Posts: 626
04-17-2007 11:04
There's a few problems with that script. Your llListenRemoves are creating a new listen then instantly deleting it, your llTriggerSound is triggering nothing at all, llGetRot doesn't need <0,0,0,0> added to it as that is the same as llGetRot on its own, the variable tim is being used for nothing other than the llSetTimerEvent (which accepts integers just as well), and you are overwriting config variables with variables from the listener event.

Your object will also rez repeatedly in the same place and trigger the sound, although this may be required behaviour.

Here's a fixed version:
CODE
integer chan=30;
integer randchan;
list times = ["5m","4m","3m","2m","1m","30s"];
integer chanhandle;
integer dialoghandle;

default{
state_entry(){
randchan=(llRound(llFrand(0x7FFF0000)) + 0xFFFF) * -1;
chanhandle=llListen(chan, "", NULL_KEY, "");
}

listen(integer ch, string name, key id, string msg){
if(ch==chan){
if(msg=="time"){
dialoghandle=llListen(randchan, "", id, "");
llDialog(id, "Please select a time.", times, randchan);
}
} else {
llListenRemove(dialoghandle);
if(msg=="5m")
llSetTimerEvent(300);
else if(msg=="4m")
llSetTimerEvent(240);
else if(msg=="3m")
llSetTimerEvent(180);
else if(msg=="2m")
llSetTimerEvent(120);
else if(msg=="1m")
llSetTimerEvent(60);
else if(msg=="30s")
llSetTimerEvent(30);
}
}

timer(){
llTriggerSound(llGetInventoryName(INVENTORY_SOUND,0),1.0);
llRezObject("Ballt", llGetPos() + <0,0,2>, <0,0,0>, llGetRot(), 0);
}
}


If you only want to listen to the owner, change the chanhandle line to:
CODE
chanhandle=llListen(chan, "", llGetOwner(), "");


If you want it to only rez once, add this line in the timer section (after the other 2 lines):
CODE
llSetTimerEvent(0);


Above is tested and working, simply type "/30 time" to get the dialog up.

Edit: Destiny posted while I was putting together a reply. Script still contains the broken llListenRemove and unused variable tim though.
ed44 Gupte
Explorer (Retired)
Join date: 7 Oct 2005
Posts: 638
04-17-2007 22:19
You have a global variable:
CODE

integer chano = ????


Then this listen event using the same channel number.
CODE

listen(integer chano, string name, key id, string choice )

The two chano's are not related to each other! They are different variables.

You only need to open one listen event and its chano will tell you what channel number the info came from. You opened listen channels with llListen. You could have up to any number of llListen commands (up to 50 I think) in a state, but you must only have one listen event!