Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Getting into a State

Gregory McLeod
Registered User
Join date: 21 Oct 2006
Posts: 278
12-23-2007 02:25
I need help understanding the switching between states.

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.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-23-2007 05:20
play != Play

State is defined as state Play in state default but named state play.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-23-2007 05:21
if I understand the problem, you have certain buttons that should only work before the main part of the game and not during it. these are sometimes triggering leftover touch events...

the solution to getting rid of extra touches would be to ignore them, not by removing the touch state, but by either filtering it (5 == llDetectedLinkNumber( i )) or by having no excutable code in it. this way touches still trigger, but they either trigger conditionally, or do nothing.

also watch out, since it's been mentioned that sometimes if the state you leave on a reset doesn't have an event type (like touch) that you DO have in you default, it won't be active like it should... not sure if that bug is still around, but test first before assuming
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Gregory McLeod
Registered User
Join date: 21 Oct 2006
Posts: 278
12-23-2007 06:34
From: Jesse Barnett
play != Play

State is defined as state Play in state default but named state play.
Sorry Jesse I made a mistake when inserting the code I used a previous version and forgot to change that eror.
I will correct the original code now.
Gregory McLeod
Registered User
Join date: 21 Oct 2006
Posts: 278
12-23-2007 06:41
From: Void Singer
if I understand the problem, you have certain buttons that should only work before the main part of the game and not during it. these are sometimes triggering leftover touch events...

the solution to getting rid of extra touches would be to ignore them, not by removing the touch state, but by either filtering it (5 == llDetectedLinkNumber( i )) or by having no excutable code in it. this way touches still trigger, but they either trigger conditionally, or do nothing.

also watch out, since it's been mentioned that sometimes if the state you leave on a reset doesn't have an event type (like touch) that you DO have in you default, it won't be active like it should... not sure if that bug is still around, but test first before assuming
Thanks for that Void. About the bug I cannot hope to compete with buggy server software. Your suggestion put me on a different thought track. If I leave the touch_start event in the state Play but include in it the same code that is used in the root Main script it would do what I want. A bit memory hungry and would have to include additional content in each of the buttons (notecard for info).
Thanks I knew someone would come up trumps. (It is usually you Void or you Jesse)
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-23-2007 08:13
From: Gregory McLeod
Thanks for that Void. About the bug I cannot hope to compete with buggy server software. Your suggestion put me on a different thought track. If I leave the touch_start event in the state Play but include in it the same code that is used in the root Main script it would do what I want. A bit memory hungry and would have to include additional content in each of the buttons (notecard for info).
Thanks I knew someone would come up trumps. (It is usually you Void or you Jesse)

well if you do go that way, then you might actually want to just use a single state, and a boolean that detects whether your game is started or not (instead of changing states).. no point repeating code
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Gregory McLeod
Registered User
Join date: 21 Oct 2006
Posts: 278
12-23-2007 08:34
I have saved a bit of code by using the same dialog input channel as the main script so didn't need the duplicate notecards, they will be served from the main script. Saves having to update them in more than one place in the future.
Thanks for all your help.

I think I have finally finished the ChinChek game, you must come over and see it some time :- Peaceful Retreat 208,58,31