playMaker

Author Topic: Support for FsmUshort [Solved]  (Read 2183 times)

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Support for FsmUshort [Solved]
« on: February 20, 2017, 02:22:32 PM »
Hi,

Is there any support for FsmUshort in custom actions? I am having some trouble converting a float to ushort and back  :'(

Thanks.
« Last Edit: February 23, 2017, 08:03:20 AM by tcmeric »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Support for FsmUshort
« Reply #1 on: February 21, 2017, 03:13:48 AM »
Hi

 Support for custom Fsmxxx is not available and not planned.

 can you explain how you intend to use this ushort and where it comes from or where you need to set it?

Bye,

 Jean

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Support for FsmUshort
« Reply #2 on: February 21, 2017, 06:50:37 AM »
Hi,

Thank you for the reply. I am basically just setting up a custom action which sets playmaker FsmVariables to script variables. It is for the VRweapons package on the asset store that allows quick building of weapons for steam VR. The playmaker actions will be release for free (I am not the author of the asset but have their permission).

In the Weapons.cs script, it is written this way:
Quote
[Range(0, 0.2f)]
public float bulletSpreadRange;
public float kickStrength;
public float rotKickStrength;
public ushort hapticStrength;
etc etc.

My script is basically the template from MdotStrange, which works otherwise. I was hoping I could dump the ushort into a float. I have never done a variable type conversion. I have done some reading up on it, but havent figured it out yet.

Quote

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
   [ActionCategory("VRweapons")]
   [Tooltip("Adjust weapon haptic time per shot in frames for VRweapons script on an object")]

   // the class must match the name of the action
   // if the action is named missleAction then that should be the name of the class
   public class  WeaponHapticAction : FsmStateAction
   {
      [RequiredField]
      // add the name of your script inside of typeof("yourScriptName"))
      [CheckForComponent(typeof(Weapon))]   

      // this is the game object the script is on
      public FsmOwnerDefault gameObject;

      [Tooltip("Adjust weapon haptic time per shot in frames.")]
      // add the variables you want in your action
      public FsmFloat HapticStre;

      // you can usually leave this alone
      public FsmBool everyFrame;

      // you are making a custom variable with the scripts type
      Weapon theScript;

      public override void Reset()
      {
         //its good practice to set your var to null at start
         gameObject = null;
         HapticStre = null;
         everyFrame = false;
      }

      public override void OnEnter()
      {
         var go = Fsm.GetOwnerDefaultTarget(gameObject);

         // you are grabbing the script from the game object and storing it in your custom variable type
         theScript = go.GetComponent<Weapon>();

         if (!everyFrame.Value)
         {
            MakeItSo();
            Finish();
         }

      }

      public override void OnUpdate()
      {
         if (everyFrame.Value)
         {
            MakeItSo();
         }
      }

      //Name your method here
      void MakeItSo()
      {
         var go = Fsm.GetOwnerDefaultTarget(gameObject);
         if (go == null)
         {
            return;
         }

         //Playmaker variable to Script

         theScript.hapticStrength = HapticStre.Value;

         //Note! Playmaker var's need .Value after them or they won't work in some cases


      }

   }
}


Also can I ask, is there any way to get variables from serialized fields from a script into playmaker? I tried the same script above (changed for floats), but i get an error about them being read only.

Script.cs

Quote
   [SerializeField]
   float maxHealth = 100f;
   [SerializeField]
   float currentHealth;

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Support for FsmUshort
« Reply #3 on: February 22, 2017, 01:32:47 AM »
Hi,

 ok, ushort is an int, so in your action you should have an FsmInt for it.
ushort.MinValue = 0
ushort.MaxValue = 65535

so you can even create an error check in the action code to warn the user when he set that int value outside this range.


then when you want to set that ushort inside the script, simply cast it like so:


theScript.hapticStrength = (uShort)HapticStre.Value;

also, don't hesitate to full name variables, "HapticStrength" is better and more readable.

as for the readonly, I am not sure, if you can send me the package with the script and action, I'll have a look.

 Bye,

 Jean



tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Support for FsmUshort
« Reply #4 on: February 22, 2017, 11:22:04 PM »
Perfect, thank you for your help. I spent more time reading about implicit and explicit casting. Your solution worked and helped point me in the right direction to learn more!

I sent you a PM regarding the serialized field.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Support for FsmUshort
« Reply #5 on: February 23, 2017, 01:53:13 AM »
Hi,

 odd, I did not received anything in my pm box.

 Bye,

 Jean

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Support for FsmUshort
« Reply #6 on: February 23, 2017, 03:31:03 AM »
Opps, maybe I sent it to your email by mistake. I sent a PM this time (I think  ;D )

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Support for FsmUshort
« Reply #7 on: February 23, 2017, 03:38:39 AM »
Hi,

 actually email is better, but haven't received one neither

Bye.
 
Jean