Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

State change weirdness

Ace Cassidy
Resident Bohemian
Join date: 5 Apr 2004
Posts: 1,228
11-08-2004 08:43
Here's a simple code snippet

CODE

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

touch_start(integer total_number)
{
llSay(0, "touched");
state foo;
}

state_exit()
{
state bar;
}
}

state foo
{
state_entry()
{
llSay(0, "in foo");
state default;
}
}

state bar
{
state_entry()
{
llSay(0, "in bar");
state default;
}
}


The "touched" msg is output once, and then the script seems to go into never-never land. Neither foo's nor bar's state_entry msg are output, and no more touch events are registered.

The wiki is down, so I can't look this up, so perhaps somebody else knows... Is this proper behavior? Is re-directing a state change from inside of "state_exit()" taboo?

- Ace
_____________________
"Free your mind, and your ass will follow" - George Clinton
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
11-08-2004 08:48
Huh, the wiki doesn't seem to mention anything at all about this particular situation. Weiiiiird stuff. I guess the poor thing is getting confused where it's supposed to be going. :)

Oh, you can still get the wiki here, btw. :)
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Issarlk Chatnoir
Cross L. apologist.
Join date: 3 Oct 2004
Posts: 424
11-08-2004 09:18
Is this what's called "pathological code"? I don't see what you are trying to achieve, if anything.
Or was it just for testing LSL behavior to weird code?
_____________________
Vincit omnia Chaos
From: Flugelhorn McHenry
Anyway, ignore me, just listen to the cow
Ace Cassidy
Resident Bohemian
Join date: 5 Apr 2004
Posts: 1,228
11-08-2004 09:43
From: Issarlk Chatnoir
Is this what's called "pathological code"? I don't see what you are trying to achieve, if anything.
Or was it just for testing LSL behavior to weird code?


The example is pathological, but solely because I tried to simplify the issue for my original post.

My motivation is that I have a rather complex set of logic that I need to evaluate to determine which of 2 states I need to go to, and I need to initiate this state change from quite a few points within my code.

Since you can't do a state change from within a function, I thought I'd do it this way. By default, I go to state foo, but in my state_exit code, I wanted to execute my logic and determine whether I really want to go to state bar.

If you or anyone else can suggest another approach, other than the obvious of putting my logic everyplace I need to make this decision, then I'll be a happy camper.

- Ace
_____________________
"Free your mind, and your ass will follow" - George Clinton
Eggy Lippmann
Wiktator
Join date: 1 May 2003
Posts: 7,939
11-08-2004 09:51
It's called a minimal test case, and it's what you should reduce your program to when encountering unexpected behavior, so that the bug hunters may be able to track down the bug more easily.
Grim Lupis
Dark Wolf
Join date: 11 Jul 2003
Posts: 762
11-08-2004 09:59
create a 4th state ("redirect";) and a global variable of type int:

CODE

integer STATE_FOO = 1;
integer STATE_BAR = 2;

integer target_state;

default
{
state_entry()
{
target_state = STATE_FOO; // set default next state
llSay(0, "Hello, Avatar!");
}

touch_start(integer total_number)
{
llSay(0, "touched");
state redirect;
}

state_exit()
{
target_state = STATE_BAR; // change next state on-the-fly
}
}

state redirect
{
state_entry()
{
if (target_state == STATE_FOO)
state foo;
if (target_state == STATE_BAR)
state bar;
}
}

state foo
{
state_entry()
{
llSay(0, "in foo");
state default;
}
}

state bar
{
state_entry()
{
llSay(0, "in bar");
state default;
}
}
_____________________
Grim

"God only made a few perfect heads, the rest of them he put hair on." -- Unknown
Ace Cassidy
Resident Bohemian
Join date: 5 Apr 2004
Posts: 1,228
11-08-2004 10:09
*smacks self upside head*

I don't know why I didn't think of this at first. The solution is rather simple. I just need to create a function that does all the logic, and then returns a value indicating which way to go.

CODE

integer NEXT_STATE_FOO = 0;
integer NEXT_STATE_BAR = 1;

integer complexStateChangeCode()
{
// code to figger out which way to go
if ( logicSaysFoo )
return NEXT_STATE_FOO;
else
return NEXT_STATE_BAR;
}

...

// inside my algorithm, wherever I need to make the state change, I just change
// what was simply 'state foo;' to :

if ( complextStateChangeCode() == NEXT_STATE_FOO )
state foo;
else
state bar;


I still have to have a single conditional at every state change, but that's a whole lot simpler than having my "complexStateChangeCode()" all over the place.

Anyway...

I'll report my simple case as a bug, and let the forum know what response I get from the Lindens. I may be told that this is expected behavior... or at least told that redirecting a state change inside of 'state_exit()' is a no-no.

- Ace
_____________________
"Free your mind, and your ass will follow" - George Clinton
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
11-08-2004 10:39
From: Ace Cassidy
I'll report my simple case as a bug, and let the forum know what response I get from the Lindens. I may be told that this is expected behavior... or at least told that redirecting a state change inside of 'state_exit()' is a no-no.


It's probably not a capital B-Bug, consider, what would you expect to happen here:
CODE

default{
touch_start(integer n) {state bar;}
state_exit() {llSay(0, "hi"); state foo}
}

state foo{...}
state bar {...}


I would expect that it hits the state_exit event, says "Hi", starts to change to state foo, which triggers a state_exit event, so the state_exit handler is called, says "Hi", starts to change to state foo, which triggers a state_exit event, so the state_exit handler is called, says "Hi", starts to change to state foo, which triggers a state_exit event, so the state_exit handler is called, says "Hi", starts to change to state foo, which triggers a state_exit event, so the state_exit handler is called, says "Hi", starts to change to state foo, which triggers a state_exit event, so the state_exit handler is called, says "Hi", starts to change to state foo, which triggers a state_exit event, so the state_exit handler is called, says "Hi", starts to change to state foo, which triggers a state_exit event, so the state_exit handler is called, says "Hi", starts to change to state foo, which triggers a state_exit event, so the state_exit handler is called, says "Hi", starts to change to state foo, which triggers a state_exit event, so the state_exit handler is called, says "Hi"...
_____________________
Sarcasm meter:
0 |-----------------------*-| 10
Rating: Awww Jeeze!
Samhain Broom
Registered User
Join date: 1 Aug 2004
Posts: 298
11-08-2004 12:08
I saw some code that suggested that a "state" could have a return. Is that possible?

CODE

default
{
state_entry()
{
//first time initialization only such as after insert/delete save
}
on_rez(integer start_param)
{
//do things in here that you need when initializing from a rez
}
//do things here to control activities
if (integer bla)
{
state one;
//do something else here after the return
}
else if (bla == 2)
{
state two;
//do something else here after the return
}
}
state one
{
//something happens here
//when done... return?
return;
}
state two
{
//next sequence happens here
return;
}


yeah I know that looks crazy... but is something like that possible?
_____________________
rm -rf /bin/ladden #beware of geeks bearing grifts
Adam Zaius
Deus
Join date: 9 Jan 2004
Posts: 1,483
11-09-2004 15:11
From: Ace Cassidy
Here's a simple code snippet
Is re-directing a state change from inside of "state_exit()" taboo?

- Ace


Yes. :)
_____________________
Co-Founder / Lead Developer
GigasSecondServer
Olmy Seraph
Valued Member
Join date: 1 Nov 2004
Posts: 502
11-10-2004 18:50
Can you say "infinite recursion"?

I knew you could.
_____________________
Some people are like Slinkies... not really good for anything, but they sure bring a smile to your face when you push them down the stairs.