|
Monica Balut
Beam-Me
Join date: 18 Feb 2007
Posts: 311
|
06-12-2007 20:44
Why doesn't on_rez get triggered if a state switch is called from state_entry? default { on_rez( integer start_param ) { llSay(0,"Rezzed"  ; } state_entry() { llSay(0,"Default state_entry"  ; state active; } } state active { state_entry() { llSay(0,"Entered Active State"  ; } } If the default state_entry causes a state switch, the on_rez event is never called when an object is first rezzed. If I remove the call to state active, then on_rez gets called. Why does this happen even though state_entry is not called when an object is rezzed?
|
|
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
|
06-12-2007 20:50
Basically, the object has to be rezzed when you add the script. So, when you add the script, "state_entry" is triggered and locks you into the "active" state. on_rez never gets a chance to trigger because there is no on_rez event in the "active" state, and no way to get back to the default state.
You need a way to get back to the default state after initializing your script, if you want the on_rez in your default. Otherwise, put the on_rez into the active state.
The default state - state_entry() event executes whenever a script is first loaded into a prim, or the script is reset, or the default state is called from another state.
|
|
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
|
06-12-2007 23:21
When script starts, it goes into state active... and state active has no on_rez event, so even if you took/rezzed the object, the on_rez won't be called since it's in a different state.
on_rez is triggered only when a prim rezzes containing a running script which contains an on_rez event handler *in the current state of the script.* As stated above, resetting a script never triggers an on_rez event because the prim is already rezzed. Try moving the on_rez event to within the "active" state, and then take the object, and then rez from your inventory and it should fire the on_rez event.
|
|
Monica Balut
Beam-Me
Join date: 18 Feb 2007
Posts: 311
|
06-13-2007 05:15
The script is stable and already loaded. I am simply rezzing the object with the script in it. It is my understanding that the object starts in the default state and the on_rez event should be called first. If I keep the "state active" statement in there, the on_rez never gets called . If I take the "state active" statement out, the on_rez does get called. The state_entry does not get called in either case, so I don't see how the script is changing to the "active" state in that situation. If it were, the llSay statement would alert me of that, and I have no indication that the script is moving to the "active" state.
|
|
Cortex Draper
Registered User
Join date: 23 Aug 2005
Posts: 406
|
06-13-2007 06:05
I would guess this is what is happening, although I am not inworld so I cannot confirm this:
The instant you put that script in the object this happens: default state entry event is triggered it changes to active state active state entry event is called
When you take the object into your inventory then out it out again, it is still in active state so doesnt trigger the onrez event from the default state. It also doesnt trigger any state entry events since its already in active state. If you had an onrez event in the active state, that would trigger.
Usefull things to note: State entry events occur before onrez events When you put a script in an object, the object is already rezzed so it wont call the onrez event until you take it into your inventory and put it out again.
|
|
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
|
06-13-2007 06:11
A script "saves" its current state when being taken into inventory and, upon being rezzed, continues from that point as if nothing had ever happened.
If an on_rez event is defined in the current active state, it will be executed. Otherwise nothing will happen.
As has been said before, you will have to define an on_rez event in the active state as well.
In fact, if you want a certain state to become active on rez you may want to add in something like... on_rez(integer X){llresetScript();} into each state that you do not wish to be active on rez.
|
|
Monica Balut
Beam-Me
Join date: 18 Feb 2007
Posts: 311
|
06-13-2007 16:45
Ok I get it. What I didn't realize is the script was being saved in the active state when I took the object into my user inventory. I was assuming it would revert to the default state when I picked it up. Since the default state is only being used to initialize things at startup, the only place I should not put an on_rez would be there. Since the owner would always be taking the object from the active state, that is the only place I really need an on_rez. If I reset the script there, it will force the script to go thru the startup routines that I wanted in the default state.
I tried that and it does what I'm looking to accomplish. Thanks for the help.
|