Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

state_entry() when is this needed

ArchTx Edo
Mystic/Artist/Architect
Join date: 13 Feb 2005
Posts: 1,993
12-16-2007 12:30
Working on this script /54/dd/230130/1.html#post1802926 made me realize that state_entry() is sometimes needed for a change of state, but I don't understand why or when it is needed. Can anyone shed some light on this?

For Example this wiki example under "states" does not use state_entry() in the default state.

CODE

default
{
touch_start(integer a)
{
state hello;
}
}

state hello
{
state_entry()
{
llOwnerSay("Hello");
state default;
}
state_exit()
{
llOwnerSay("Goodbye");
}
}


And this example under state_entry() does use it.

CODE

default
{
state_entry()
{
llSay(0, "Hello, Avatar!");
}
}


As best I can guess, if you want the script to do something as soon as it enters a state you need to use state_entry(), otherwise the script waits for an event to trigger whatever action is in that state. Is that it?
_____________________

VRchitecture Model Homes at http://slurl.com/secondlife/Shona/60/220/30
http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=2240
http://shop.onrez.com/Archtx_Edo
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
12-16-2007 12:52
From: ArchTx Edo



As best I can guess, if you want the script to do something as soon as it enters a state you need to use state_entry(), otherwise the script waits for an event to trigger whatever action is in that state. Is that it?
[/php]

Yes.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-16-2007 15:21
Actually it is more then just that. In state entry you can define your global variables that will not change, pos = llGetPos() for instance, or owner = llGetOwner(), so that you do not make the server repeatedly have to get the same info. Also a good place to define listen handles etc.

Sometimes you will find that you need to set a global variable to an empty string or list, if you don't want to carry the info over from another state by declaring it string = "" etc.

If you need a listen as soon as the script is running then state entry would be the place to call it.

Many, many, many, many uses.
_____________________
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-16-2007 15:57
I think at one point the compiler didn't like not having it in the default state....

only use the events you need, states must have at least one event to compile
_____________________
|
| . "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...
| -