playMaker

Author Topic: Send Event twice in the same State  (Read 1772 times)

Wayne191

  • Playmaker Newbie
  • *
  • Posts: 28
Send Event twice in the same State
« on: April 26, 2017, 03:15:44 AM »
Hi,

I tried to use SendEvent to two different event in the same state (one after another) and the program gets stuck. Was there anything wrong with my logic? How can I change it?

Thanks.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Send Event twice in the same State
« Reply #1 on: April 26, 2017, 03:43:18 AM »
Hi,

 I don't think this is the cause of the lock, but rather one of the event is a transition that brings you back to the same state and you reach a deadlock this way.

 also, can you explain the logic behind sending two different SendEvent in the same state? that doesn't make sense, but you may have a logical case for sure.

 Bye,

 Jean

Wayne191

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Send Event twice in the same State
« Reply #2 on: April 26, 2017, 10:40:18 PM »
Hi,

Thanks for your reply.

I am making a monopoly kind of game:
 
Game Start

1. Player 1: both Roll and End Turn Button show and clickable.
    Player 2: both Roll and End Button not show.

2. Player 1 finish his turn by click on End Turn Button.

3. Player 1: both Roll and End Turn Button now show.
    Player 2: both Roll and End Turn Button show and clickable
4. Player 2 finish his turn by click on End Turn Button and it goes back to process 1

My approach was deactivate Player2's Roll and End Turn Button at the beginning and activate both button once Player1 click on his End Turn button. That's why two Send Event were sent in the same state.

Also, I use Activate Game Object action to Show/Now Show the button. Not sure if this is the right action I am supposed to use?

I am new to this and trying to find a way to work it out. Thanks.
« Last Edit: April 26, 2017, 11:18:37 PM by walecowbe »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Send Event twice in the same State
« Reply #3 on: April 27, 2017, 02:04:00 AM »
Hi,
Are the send events pointing to a different fsm each or both to the same fsm?

If to the same fsm that might be the problem as it would send the first event and immediately send the next one and might not have finished the actions connected to the 1st send event.

If that is not the case, maybe you can make some picture or a video with your states/action showing your issue.

Wayne191

  • Playmaker Newbie
  • *
  • Posts: 28
Re: Send Event twice in the same State
« Reply #4 on: April 27, 2017, 05:08:47 AM »
Hi,

Attached are the States and Actions. Game Object Player01 and Player02 are where the ROLL buttons are and P1 P2 END TURN are two End Turn Buttons for the two players.

After I set Start State to be the same as gotoEndTurnButton2 and remove sendEvent to P2 End Turn gotoEndTurnbutton2, it works ok, but the game start with both players end turn button appear and clickable which was not my intention.

I guess I am also confused for a few concepts:

1. Is it the right approach to use activate game object to show and hide buttons?
(In the same state I activate/deactive 4 different game object)

2. Start State and Global transitional event: are they conflicted?

3. When I activate an object, does that mean it gets sent to the Start State?

Thank you for your help!

« Last Edit: April 27, 2017, 05:31:57 AM by walecowbe »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Send Event twice in the same State
« Reply #5 on: April 28, 2017, 04:49:40 AM »
Hi.

The way you set this up look very prone to problems, but i will explain a bit how this way can work.

On screenshot 4 i can see that the send event is on top and the activate is on the bottom.
Actions will be triggered from top to bottom so try setting the send event last.
also you can right-click in the state window and select 'action sequence' this will take care that the actions will be done in sequence, which means that it will way each action till its done.

If action sequence is off multiple actions will still start in sequence but will not wait till the actions are done.

so if for example in screenshot 3  if the action 'Activate Game Object' (P2 End Turn)
takes longer to finish than the 'Send Event' (P2 End Turn)
it might not trigger the event as it (P2 End Turn) would not be active yet.

But when sequence is enabled it should work.

for different ways :

You can also disable fsm's instead of using Activate GO's

or make a state called idle.

You can also swap images on the canvas for player 1 / 2
and combine the 2 player fsm's into one.

If you can make a video on how you set it up i can see if i can make a video how i would set it up.
Or you can pm a link to your project and i can test it, and show you a different way