In the game I have developed the opening phase is the selection of player's colors. To do this I have positioned triangluar buttons on the top face of the board. Some of these are set Alpha=1 when the number of players is chosen. A player clicking on a colored button causes the script it contains to send a message to the Main script in the root prim that that color has been selected and by whom. The button must then prevent other players from selecting it so I use a switch which is set on the first touch_start event. If that switch is set then further touches get a dialog saying the player was too late in choosing that color and to try another. When the selection phase is complete I want the buttons all to disappear so set them Alpha=0.
Now the problem while the game is in progress anyone clicking the board top where the buttons are (but invisible) will cause the button script to say they are too late to try... when what I want is the touch to be passed to the root script for handling (provide information, allow termination of game, etc...). llPassTouches seems only to work to stop touches being passed.
I therefore tried to change the state of the script in the button to one in which the touch_start event is missing but this causes a problem. It appears that late clicks are queued and are presented to the touch_start event handler in the default state when that state is returned to at the end of the game and before the Root script can reset the board.
I thought that all pending events were cleared on a state change.
So what is happening?
CODE
// Global constants
integer CHANNEL4321 = 4321; // Prefix receiving channel
// Global variables
integer Prefix; // Prefix for llwhisper commands
integer CHANNEL2001; // OUTPUT channel
integer CHANNEL2009; // INPUT S/Uns-electable channel
integer selected = 0; // selected = FALSE
integer selectable = 0; // selectable = FALSE
// Functions
Init()
{
CHANNEL2001 = Prefix + 2001;
CHANNEL2009 = Prefix + 2009;
llListen(CHANNEL2009,"",NULL_KEY,"");
llListen(CHANNEL4321,"",NULL_KEY,"");
} // end of Init function
// States
default
{
state_entry()
{
Init();
} // end of state_entry event block
touch_start(integer total_number)
{
if (selectable)
{
integer i;
list Btns = ["OK"];
for (i = 0; i <= total_number; ++i)
{
if (!selected)
{
llDialog(llDetectedKey(i),"You have selected Red.",Btns,99);
selected = 1;
llSetAlpha(0.0,ALL_SIDES);
llWhisper(CHANNEL2001,"0" + llDetectedName(i));
} // end of !selected block
else
{
llDialog(llDetectedKey(i),"Too late, choose another color.",Btns,99);
} // end of else block
} // end of for loop
state Play;
} // end of selectable condition
} // end of touch_start event block
listen(integer channel, string name, key id, string message)
{
if(channel == CHANNEL2009)
{
if(message == "Selectable")
{
selected = 0;
selectable = 1;
llSetAlpha(1.0,ALL_SIDES);
}else // end of Selectable block
if(message == "Unselectable")
{
selected = 0;
selectable = 0;
llSetAlpha(0.0,ALL_SIDES);
} // end of Unselectable block
}else // end of CHANNEL2009 blocks
if (channel == CHANNEL4321)
{
if (llGetSubString(message,0,5) == "Prefix")
{
llOwnerSay("Prefix: " + (string)Prefix);
} // end of Prefix block
} // end of CHANNEL4321 block
} // end of listen event blocks
link_message(integer sender_number,integer number,string message,key ID)
{
if(sender_number == LINK_ROOT && message == "PfxLod")
{
Prefix = number;
Init();
} // end of PfxLod block
} // end of link_message event block
} // end of default state
state Play
{
state_entry()
{
llListen(CHANNEL2009,"",NULL_KEY,"");
}
listen(integer channel, string name, key id, string message)
{
if(channel == CHANNEL2009)
{
if(message == "Selectable")
{
selected = 0;
selectable = 1;
llSetAlpha(1.0,ALL_SIDES);
state default;
} // end of Selectable block
} // end of CHANNEL2009 block
} // end of listen event block
} // end of Play state
I am sorry if this seems long and complicated but I thought I would include the code the first time instead of waiting for someone to ask for it.
Oh how I wish the LINDENS re-instate BBcode in the forums that looks hideously complex.