State Machine

New releases and general discussions.

Post » Sun Feb 07, 2010 4:38 am

[quote="Aeal5566":3ap1k3mg]Construct is a giant FSM. If this -> do this. Which is almost exactly what a FSM does.[/quote:3ap1k3mg]... not exactly the same.
[quote:3ap1k3mg]What I think people are actually asking for here is a Boolean type value that is either on of off. Or triggers once and then never runs again.[/quote:3ap1k3mg]
Nope, not at all.

That said, you CAN make a FSM in Construct, it's not hard at all, just harder to read and mantain (state name typos, for example).

[list:3ap1k3mg]
[*:3ap1k3mg]Use a global var to hold the state[/*:m:3ap1k3mg]
[*:3ap1k3mg]compare the status var to check for the current state.[/*:m:3ap1k3mg]
[*:3ap1k3mg]when changing the state, you directly change the value of the var.[/*:m:3ap1k3mg]
[*:3ap1k3mg]for On Enter State patrolling, you would do this instead:
+ System: Trigger once
+ System: global('state') Equal to "patrolling"[/*:m:3ap1k3mg]
[*:3ap1k3mg]for On Leave State patrolling, you would have to either use a function objects or copy all the actions to each of the events that may change the state to another one.[/*:m:3ap1k3mg][/list:u:3ap1k3mg]
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Sun Feb 07, 2010 8:59 am

Sure, it is easy, but it is also tedious and I use it in nearly every project. It would cut a lot of development time down if there was a plugin for that.

Moreover, I'd also like to have more or less independent FSM cells (one for each AI entity). It is easy to design AI using state machine, however in current form it is very tedious. Then some state machines run in parallel, so they shouldn't interfere with each other. For example game and GUI states, if you only use one global for states, as soon as you change the state, say open a game menu, there is a risk of breaking the game context.

What I want is a FSM plugin that would allow me to create independent enclosed machines or one big huge tree of states, whatever suits the purpose. It would also make managing events easier - when your caveman is hungry, he goes to hunt, thus activate Hunt state machine which handles hunting procedure. As soon as it finishes, it returns to whatever the player was doing before hunting. Then there'd be interrupts, such as spotting a lovely cavewoman, then Romance state machine is invoked. Some interrupts would stop the current procedure altogether or just pause it and resume after the interrupt is completed.

That's a lot of code to do.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sun Feb 07, 2010 6:49 pm

[quote="madster":1ef4my73] Aeal5566 wrote:Construct is a giant FSM. If this -> do this. Which is almost exactly what a FSM does.

... not exactly the same.[/quote:1ef4my73]

I didn't say it was exactly the same but essentially that is what construct is and I even said that. read posts before you reply.

[quote="madster":1ef4my73] What I think people are actually asking for here is a Boolean type value that is either on of off. Or triggers once and then never runs again.


Nope, not at all.[/quote:1ef4my73]

Again if you read the original post mipey gave examples of what he wanted.

OnStart, OnStop, Walking, Standing

OnStart, OnStop are triggers and he also gave the examples of StartofLayout start of game. The start and stop would trigger when there was a state change but essentially walking and standing are Boolean values that are either true or false, and when the value changed you would would call the trigger. and instead of just saying something like "nope not at all" actually contribute something to the topic, we know you can make a state machine in construct we were talking about what a plugin would look like for it.


Now mipey
can you answer some of my questions about how states are defined. Are they runtime edittime etc.
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Sun Feb 07, 2010 7:02 pm

I'm yet to be convinced what the fuss over finite state machines is. A concrete example showing how useful a .cap designed this way would be would help persuade me. Right now I can't see any benefit over the usual event system.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,518

Post » Sun Feb 07, 2010 7:03 pm

Edit time, I guess; states would be part of the engine, which is not altered in runtime. We'd have to define the state machines in edit time. There is no point in altering the state machine in runtime (at least none that I can see right now). Basically create sprites, families, stuff, then create state machines, maybe object or family specific, maybe free (to handle transitions, slideshows or whatever).
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sun Feb 07, 2010 7:12 pm

The only reason I was looking in to making it is because I'm taking a c++ class and im kind of bored in it so I wanted to try some more in depth things so i figured i would make a plugin since i havent really contributed anything recently.
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Sun Feb 07, 2010 7:43 pm

[quote="Aeal5566":ajo57782]i havent really contributed anything recently.[/quote:ajo57782]
[quote:ajo57782]read posts before you reply.[/quote:ajo57782]
[quote:ajo57782]actually contribute something to the topic[/quote:ajo57782]
How about not doing that anymore? that would be an appreciated contribution.



Now, back on topic and disregarding needlessly aggressive replies:
An FSM differs from boolean if/else logic in the same way if/else logic differs from a switch statement in C, just its organization. But then again, you don't really need any organizational logic except compares and jump, you could do that in Assembler and there's no limitation there... only it's really tedious.

Mipey: if you use a private var instead of a global var for your FSM, you'd have a private FSM. To have hierarchy within a FSM, you do something like this:

FSM1(A,B,C) has a child FSM2(X,Y,Z) in state B. All of FSM2 events would then be as a subevent of "FSM1 On State B".

Having interruptions is about the same deal, all a plugin would do is make it really easy to read (and as I explained before in my unread "actual contribution to the topic", provide the On Leave event which is really messy without an FSM condition)
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Sun Feb 07, 2010 9:04 pm

Thread approaching lock unless you turn down the passive aggressiveness.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,518

Post » Sun Feb 07, 2010 10:26 pm

For an on leave condition, you can simply check for the state again. Like:

If value 'mode' = "standing"
(subevents)
- Trigger once (on start)
- on jump pressed, set mode to "jumping"
- if mode does not equal standing (on leave)
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Mon Feb 08, 2010 12:19 am

Ash,
It would be a shame to lock such an interesting thread.

I'd prefer to see the people getting out of hand dealt with.
I've always found Aeal5566's views interesting, but it seems Madster would prefer to tell rather than being told. :) :)

Anyway, I've almost always used a state machine when programming in C++.
Maybe not what "some" people would call a State Machine, but there's a lot of power in using a system based on variable states.

Krush.
B
2
S
2
G
3
Posts: 406
Reputation: 2,062

PreviousNext

Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 0 guests