# Turn-based Sequences

Get help using Construct 2

### » Thu May 17, 2012 7:29 am

How would I create a turn which loops between Player A & B.

I was thinkin around the lines of this pseudocode

---LOOP---
1 StartStep PlayerA
2 PlayStep PlayerA
3 AttackStep PlayerA
4 EndStep PlayerA
5 StartStep PlayerB
6 PlayStep PlayerB
7 AttackStep PlayerB
8 EndStep PlayerB
---LOOP---

Loop these events until winner.

B
5
Posts: 38
Reputation: 501

### » Thu May 17, 2012 7:36 am

Basically a finite state machine.

A bunch of conditions like this:

+ GameState == "StartStep PlayerA"
> do stuff required for this step
> if done then GameState = PlayStep PlayerA

+ GameState == "PlayStep PlayerA"
> do stuff required for this step
> if done then GameState = AttackStep PlayerA

and so on. Basically you have a global variable that holds the current state and a bunch of conditions for each of states. While a state is true, that stage is executed, until it is done, at which point the state is changed to the next stage.

At the last stage, you point back to the first stage.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

### » Thu May 17, 2012 7:53 am

Cool.

So in my Event Sheet, currently I have Groups for each action that players will be doing: Restore, Retreat, DrawCard, Pass, PlayCard, RevealCard, and so on...

In your explained 'State', that become true, I would activate the Groups according to what Actions can be done at the time during that State.

Aka a basic FSM Model for turn-based sequences?

How would I make it PlayerB's turn?
B
5
Posts: 38
Reputation: 501

### » Thu May 17, 2012 7:58 am

At end of PlayerA's turn you set state to start of PlayerB's turn.

Try with a simple, dumbed-down prototype, until you figure the most convenient way out!Mipey2012-05-17 07:59:50
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

### » Thu May 17, 2012 8:01 am

Got It. This leads right into this question though and then i can get things rollin. How should I have Card Objects?timbanon2012-05-17 08:02:59
B
5
Posts: 38
Reputation: 501

### » Thu May 17, 2012 8:12 am

[QUOTE=Mipey] Basically a finite state machine.

A bunch of conditions like this:

+ GameState == "StartStep PlayerA"
> do stuff required for this step
> if done then GameState = PlayStep PlayerA

+ GameState == "PlayStep PlayerA"
> do stuff required for this step
> if done then GameState = AttackStep PlayerA

[/QUOTE]

Would GameStates be Groups with conditions and actions in them?
B
5
Posts: 38
Reputation: 501

### » Thu May 17, 2012 8:14 am

Sure, you just disable and enable groups as needed.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

### » Thu Nov 15, 2012 2:07 am

Sorry to dig up an old post, but i've been searching and reading through many posts and really need help with my domino game.
My FSM works via:

+Group 1 = Active
> loop for domino
> if domino found - play it
> if not domino - set group 2 active
+Group 2 = Active
> loop for domino
>> if domino found - play it
>> if not domino - set group 3 active
etc.....

My AI:
+Every Tick
+ Turn not=1
> Set group 1 active

Notes: all groups are deactivated on start and deactivated before going to another group.
My problem is adding a delay. My game has 4 players (3 cpu). I want a cpu to play then after a few secs I want the other cpu to play, until its the user's turn.
Currently, after the user plays, all 3 cpu players play instantaneously.
I've tried C2's 'wait action' and that gave me horrors...
I gave up for a couple months, now i'm back to hopefully get my game completed
B
4
Posts: 4
Reputation: 358

### » Thu Nov 15, 2012 10:56 am

After many months and no sleep last nite I finally got the dam 'wait' ting working....
I had to mix my fsm methods. I was using groups for everything (set active, set deactive), which didnt work with the wait action. So I changed only my cpu AI to use a status variable as Mipey mentioned, and (the needed part) set the status to 'wait' during the wait , lol

+After each play - set status to 'wait'

+(group WAIT) if status='wait'
>wait 5 seconds
>set status to 'AI'

+(group AI) if status='AI'
> do stuff
> set status to 'AI-2'
+(group AI-2) if status='AI-2'
> do stuff
> set status to 'AI-3'
....etc

I'm not sure why (setting wait group active, then wait 5 secs, then deactivate wait group, then set AI group active) didn't work for me.

Unfinished, but you can take a look here:
Click 'Play' on the intro, then 'Ok' for name, then click 'Deal'.
The game will auto-pose unless you have 6:6 and when it is your play it will put the domino you click on the correct location.

http://chezral.6te.net/Domino/index.html
B
4
Posts: 4
Reputation: 358