playMaker

Author Topic: How to write actions properly?  (Read 2906 times)

Mayhem

  • Full Member
  • ***
  • Posts: 171
How to write actions properly?
« on: November 14, 2013, 08:31:53 AM »
Hey there. So the last couple of days I'm trying to write my own actions, but the problem is: I can't to get them to work properly.

The main issue is, that I don't know exactly how to write them? When do I use which PlayMaker-function (Reset, OnEnter, OnUpdate, and so on), which PlayMaker variables are needed and so on.

I looked up the wiki and youtube but didn't find anything useful in order to team how to write them. (maybe I just didn't look good enough)
I also looked at already implemented actions, but I don't understand how they work.

It would be great if there would be a Step-For-Step guide in order to create own actions for non-programmers (like me) :)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How to write actions properly?
« Reply #1 on: November 14, 2013, 11:29:36 AM »
Have you taken a look at some existing action scripts? I usually just glance through actions that do something similar to what I want and see how they're constructed.

Reset is just used to define base/reset values for the variables you are using.
OnEnter is the first time the script is run
OnUpdate is run every time it is updated (every frame)

Any examples of what you're trying to make?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Mayhem

  • Full Member
  • ***
  • Posts: 171
Re: How to write actions properly?
« Reply #2 on: November 14, 2013, 12:20:24 PM »
As said, I did take a look, but I feel a little bit overwhelmed since I don't know where to start :/

So for example:

When I use OnUpdate, that means my action will have a Checkbox for the "Every Frame" Option, won't it?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How to write actions properly?
« Reply #3 on: November 14, 2013, 12:54:00 PM »
No, its not implied. If you notice in the actions that have the checkbox for every frame there is something like this in OnEnter:

Code: [Select]
public override void OnEnter()
{
DoWhateverStuff();

if (!everyFrame)
{
Finish();
}
}

So basically {go do the method DoWhateverStuff}, then {if not every frame, finish} which ends the action. Otherwise it would continue running OnUpdate. EveryFrame off just forces the action to stop, and its nothing more than a bool.

OnUpdate would look something like this...

Code: [Select]
public override void OnUpdate()
{
DoWhateverStuff();
}

and then somewhere below that would be whatever you wanted it do to.

Code: [Select]
void DoWhateverStuff()
{
myWhateverBool == false;
}

In the beginning of the script you need to define the tooltips and reset values of variables. They look something like this..

Code: [Select]
{
[ActionCategory(ActionCategory.MyCustomStuff)]
[Tooltip("It does Whatever Stuff, and is very useful.")]
public class MyWhateverStuffAction : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("Some bool variable.")]
public FsmBool myWhateverBool;

[Tooltip("Repeat every frame.")]
public bool everyFrame;


RequiredField and UIHint are optional, but help construct a stable and informative action.

Reset would look something like this...

Code: [Select]
public override void Reset()
{
myWhateverBool = null;
everyFrame = false;
}

Of course this is all just gibberish code, but hopefully explains a little bit about how it works. You can find more information in the Assembly Browser, and of course by looking at other actions and directly seeing the affect of the code on the UI. I don't know of any other way to dig deeper and have found that examining the code in current actions to be the best way for me to figure things out.

Hope that helps.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to write actions properly?
« Reply #4 on: November 15, 2013, 06:57:38 AM »
Hi,

 Yes, indeed this is something thet needs doing.

 The best way to go about this is to find an existing action that is similar in interface. for example, you want to play around with a transform position, then you should look at the SetPosition for example, and then you can see how it's been build.

 I know it's thin, but it's actually how I learned myself :) you take an existing action and you go line by line and you don't move to the next line until you haven't fully grasp what it's doing, and ask a question when you are stuck on a specific line, and we'll help.

 I actually NEVER startd a custom action from scratch, I always copy one that exists and is close enough to what I want to achieve and then modify it and takes bits and bobs of other actions feature the missing ingredients.

Also, are you aware that PlayMaker has a wizard tool to build a custom action? it's in the Tools menu. It allows you to define the basics shape of it and you only then have to fill in the blanks pretty much.

bye,

 Jean

Mayhem

  • Full Member
  • ***
  • Posts: 171
Re: How to write actions properly?
« Reply #5 on: November 16, 2013, 09:50:30 AM »
Alright, thanks for the hints and tips guys :)