playMaker

Author Topic: JavaScript action example  (Read 8797 times)

legend411

  • Playmaker Newbie
  • *
  • Posts: 6
JavaScript action example
« on: March 09, 2012, 03:13:56 PM »
It appears there are no examples of custom actions written in JavaScript... I converted the example from the api reference to JavaScript, if anyone wants an example. Works just fine :)

Code: [Select]
import System;
import HutongGames.PlayMaker;

@ActionCategory(ActionCategory.Time)
@Tooltip("Gets system date and time info and stores it in a string variable")
public class GetSystemDateTime extends FsmStateAction{

@UIHint(UIHint.Variable)
@Tooltip("Store System DateTime as a string.")
public var storeString : FsmString;
@Tooltip("Optional format string. E.g., MM/dd/yyyy HH:mm")
public var format : FsmString;

public function Reset(){
storeString = null;
format = "MM/dd/yyyy HH:mm";
}

public function OnEnter(){
storeString.Value = DateTime.Now.ToString(format.Value);
Finish();
}

}
« Last Edit: February 16, 2015, 01:19:29 AM by jeanfabre »

upigu

  • Playmaker Newbie
  • *
  • Posts: 1
Re: JavaScript action example
« Reply #1 on: March 14, 2012, 03:23:37 AM »
 :) :) :) :)

Great!! I'm start learning javascript and this is what I need!

Thanks I will try it!

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: JavaScript action example
« Reply #2 on: March 14, 2012, 09:52:55 AM »
Thanks legend411! I'll add it to the docs... :)

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: JavaScript action example
« Reply #3 on: March 16, 2012, 11:23:53 PM »
I think:

Code: [Select]
import HutongGames.PlayMaker.Actions;
Should be:

Code: [Select]
import HutongGames.PlayMaker;

pneill

  • Playmaker Newbie
  • *
  • Posts: 32
Re: JavaScript action example
« Reply #4 on: May 09, 2012, 01:08:34 AM »
For a  javascript action, does anyone know what the proper is to show the UseVariable UI hint?

Code: [Select]
public function Reset(){
foo = new FsmFloat { UseVariable = true };
}

Doesn't seem to work.

pneill

  • Playmaker Newbie
  • *
  • Posts: 32
Re: JavaScript action example
« Reply #5 on: May 10, 2012, 11:40:15 AM »
Bump this thread.  Anyone have an idea?  Alex?  Jean?   It's kind of a blocking item for me right now.

Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: JavaScript action example
« Reply #6 on: May 10, 2012, 12:14:21 PM »
:)

 I was actually waiting for someone to reply...

 I am for example unable to define a variable as required...

 Bye,

 Jean

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: JavaScript action example
« Reply #7 on: May 10, 2012, 02:31:34 PM »
I'm not at my computer, but I believe in javascript you put @ in front of an attribute instead of using the square brackets.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: JavaScript action example
« Reply #9 on: May 10, 2012, 04:12:26 PM »
Hey,

 You passed the 1000's post Alex! I need to post more "good", "nice" and "ok" to overtake you  ;)

 

pneill

  • Playmaker Newbie
  • *
  • Posts: 32
Re: JavaScript action example
« Reply #10 on: May 11, 2012, 12:41:32 AM »
hmmm, I think I might not have exactly communicated what the issue is that I'm looking to resolve.  I've got Variable UI hint working fine, what I'm trying to figure out is how to incorporate the variable toggle switch that some actions have along with the simple drop down.

So my question is, how can I add that functionality to a JS custom action?  I want it possible for folks on my team to be able to use either a variable or just fill in a number or this particular action.

From reviewing the actions it appears this is done via a  UseVariable attribute that's is added in the reset method, but your suggestion above seems to imply this is done with the variable declearation UI.hint.  Is that right?

Sample code would be appreciated! ;D

Thanks

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: JavaScript action example
« Reply #11 on: May 11, 2012, 12:50:16 AM »
You should get that UI just by declaring a public FsmFloat variable.

Are you not seeing that?

The UIHint.Variable attribute tells the editor to show a variable selection popup. E.g., to store a value.

{ UseVariable = true } in Reset(), that just means the variable toggle is pressed by default. Sometimes that makes more sense in the context...

pneill

  • Playmaker Newbie
  • *
  • Posts: 32
Re: JavaScript action example
« Reply #12 on: May 11, 2012, 01:05:23 AM »
Ah!  Now I see what was happening.  It looks like when I declare the variable if I include the UIHint.Variable that I would get this property.  Looks like it's the opposite.  Is that by design?