playMaker

Author Topic: Finish(); don't actually finish?  (Read 741 times)

nFighter

  • Beta Group
  • Full Member
  • *
  • Posts: 174
    • multiplayer adult fighting
Finish(); don't actually finish?
« on: January 18, 2023, 03:25:09 AM »
Hello, folks. I feel confused.
I started my action like

Code: [Select]
public override void OnEnter()
        {
Fsm.Event(isError);
Finish();
Debug.Log("Must be finished");

and expected this playmaker action to fire isError event and do nothing. But instead, I see the debug message in the console (and all other scripts from the action executed as well). Why it's happening? Is it a bug or I missed some concept? How should I actually abort my playmaker action?
indie developer of multiplayer adult fighting
http://nakedfighter3d.com

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Finish(); don't actually finish?
« Reply #1 on: January 20, 2023, 02:13:01 AM »
It will send the error event, then do the Finish event.
and because the finished event is probably not triggered in the same frame it will still also send the debug.

in a state if you want it not to continue you should not use a 'FINISHED' transition.
you can also make your event to have a true or false event
So isError and notError event.

if you remove the Finish();
then the action will not be finished, but thats not advisable to do this way.

nFighter

  • Beta Group
  • Full Member
  • *
  • Posts: 174
    • multiplayer adult fighting
Re: Finish(); don't actually finish?
« Reply #2 on: January 28, 2023, 01:50:41 AM »
Sorry, I still don't understand: what exactly do I need to do to prevent Debug.Log("Must be finished"); from running in this example?
indie developer of multiplayer adult fighting
http://nakedfighter3d.com

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Finish(); don't actually finish?
« Reply #3 on: January 28, 2023, 03:02:55 AM »
Hi.
The debug log line will always be triggered.

Finish(); tells the 'State' fsm script that this action is "fininshed'
this 'state' fsm script will look if all action in the state are finished, then send the "FINISHED' event

Look for example to some Action scripts that have a every frame check box.
In the script it will only send the Finish() event if every frame is false.

Finish() does not mean that the script itself has ended (so if you put things after it, they still can be triggered).

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 254
Re: Finish(); don't actually finish?
« Reply #4 on: January 28, 2023, 09:28:49 PM »
Hmmm that’s interesting. I have been writing several custom actions now and I would have sweared that finish(); in fact triggers the end of the action no matter the code after. And as the OP points out can be used to finish the action in different circumstances.

The example of the “every frame” option is actually exactly that: if false it immediately triggers the end of the action and under no circumstances it will trigger the code in update.

So what the OP wrote should actually not execute any of the code after this method.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Finish(); don't actually finish?
« Reply #5 on: January 29, 2023, 01:20:10 AM »
Hi.

Try putting 2 actions in 1 state

action 1 set as every frame (for example 'Set Position' action.

action 2 make a custom one and set a finish and add stuff after the finish();

the C# script does not know that finish(); should end the script as its just sending an event to the fsm script so that the fsm knows that this action has completed. and if all actions in that state are 'Finished' that it can send the "FINISHED" event

To end a C# script it needs to use for example : return;
but it would then also make no sense to place something after that (unless the return is conditional, for example 'if variable X = true return;
so if not true it will continue.


nFighter

  • Beta Group
  • Full Member
  • *
  • Posts: 174
    • multiplayer adult fighting
Re: Finish(); don't actually finish?
« Reply #6 on: February 01, 2023, 03:55:22 AM »
I have returned to the topic to say I found a solution but as I see it was already proposed  ;D
I'm using conditional return; to abort the script at certain places!
indie developer of multiplayer adult fighting
http://nakedfighter3d.com