Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

sates and dialogues?

Grigoriy Petrov
Registered User
Join date: 23 Feb 2007
Posts: 3
02-27-2007 01:12
Hi,

Anyone have any idea why this script doesn't work as intended, its nonsensical but its made to highlight my issue, basically after entering state picked, it gets through state_entry() but the dialog never appears and you cannot re-touch it as the option is greyed out?

CODE

integer menu_handler;
integer menu_channel;
list menu_example = [ "yes", "no", "cancel" ];
list submenu_example = [ "yes_0", "no_0", "cancel_0"];

default {

state_entry() {

// do stuff here
state idle;

}

on_rez(integer start_param) {

llResetScript();

}

}

state idle {

timer() {

// do stuff periodically here

}

state_entry() {

llSay(0, "idle...");

}


touch_start(integer total_number) {

state running;

}
}

state running {

state_entry() {

llSay(0, "running...");

}

timer() {

llSetTimerEvent(0.0);
// anyone know how llListenControl() works?
llListenRemove(menu_handler);
}


touch_start(integer total_number) {

menu_channel = -42;
menu_handler = llListen(menu_channel,"","","");
llDialog(llDetectedKey(0), "example menu", menu_example, menu_channel);
llSetTimerEvent(15.0);

}


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

if (channel == menu_channel) {

llSetTimerEvent(0.0);
// anyone know how llListenControl() works?
llListenRemove(menu_handler);

// is llListFindList() redundant seeing as just testing choice here works?
if (llListFindList(menu_example, [choice]) != -1) {

if (choice == "yes")
state picked;

else if (choice == "no")
state picked;

else { // cancel

llSay(0, "bye");
state idle;
}

} else {
llSay(0, "invalid selection");
state idle;
}
}
}
}


state picked {

state_entry() {

llSay(0, "picked_yes...");
menu_channel = -42;
menu_handler = llListen(menu_channel,"","","");
llDialog(llDetectedKey(0), "example menu", menu_example, menu_channel);
llSetTimerEvent(15.0);
llSay(0, "this prints");

}

timer() {

llSetTimerEvent(0.0);
// anyone know how llListenControl() works?
llListenRemove(menu_handler);
}

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

// never reached?
if (channel == menu_channel) {

llSetTimerEvent(0.0);
// anyone know how llListenControl() works?
llListenRemove(menu_handler);

// is llListFindList() redundant seeing as just testing choice here works?
if (llListFindList(menu_example, [choice]) != -1) {

if (choice == "yes_0")
llSay(0, "picked yes");

else if (choice == "no_0")
llSay(0, "picked no");

else { // cancel

llSay(0, "bye");
state idle;
}

} else {
llSay(0, "invalid selection");
state idle;
}

//state idle;
}
}
}
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
02-27-2007 02:42
After you change states, you're trying to present a dialog to llDetectedKey(0), but there isn't any such thing any more outside of touch or some other similar event. Declare a global and assign it the value of llDetectedKey in the first touch event, then use that variable throughout your script.

Oh and when posting code, please wrap it in [ php ] and [/ php ] tags (minus the spaces) to make it much more readable, with proper indents and stuff. :)


edit: if you want to be able to touch it in the new state, you need to add a touch event handler there too.