playMaker

Author Topic: Custom Action FsmVar Convert  (Read 1685 times)

Luceid

  • Playmaker Newbie
  • *
  • Posts: 16
Custom Action FsmVar Convert
« on: September 22, 2023, 07:23:36 PM »
Hello,
I am building some custom actions to interface with a third party asset that I am using on my project. I need to be able to get/set variables on a script. I have successfully managed to nail down the get action. I accomplished this by using a line like this:
Code: [Select]
tempFloat = root.moduleParameters.GetFloat(strings[i].Value);
PlayMakerUtils.ApplyValueToFsmVar(Fsm, variables[i], tempFloat);

The first line gets the third party float and stores it in a tempFloat, the second line copies that value to the FsmVar to be useable in PM. So far so good.

My problem comes when I try to do the opposite, and convert my FsmVar to a local variable like tempFloat. I have scoured the API for custom actions and I can't find a single method that doesn't end in something like this:

"Cannot convert type hutonggames.playmaker.FsmVar to type float."

Is there a reliable way to convert from FsmVars to local variables like ints, floats, strings, bools etc? I know the FsmVar knows what type it is, because I have successfully used this in my get function to filter them:
Code: [Select]
if (variables[i].Type == VariableType.Float)

Thank you for any help!

Edit: also to clarify, I am using FsmVars rather than specific types like FsmFloats because I want to have a dropdown where I choose to get/set any number of variables that aren't necessarily the same type.
« Last Edit: September 22, 2023, 07:33:45 PM by Luceid »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Custom Action FsmVar Convert
« Reply #1 on: September 23, 2023, 05:57:13 AM »
Hi.
Try looking at the 'Get/Set Fsm Variable' actions as a reference.

Luceid

  • Playmaker Newbie
  • *
  • Posts: 16
Re: Custom Action FsmVar Convert
« Reply #2 on: September 23, 2023, 07:48:58 AM »
Those were actually the first ones I modeled my action after! Glad we had the same thought.

But I already looked into it, and it uses NamedVariables and INamedVariables to get variables from other FSMs, which is not what I need to do.

And furthermore, if I try to use NamedVariables and INamedVariables, they still cannot convert to local FsmFloats or floats for example. I get a similar error of InamedVariable cannot be converted to type ___

Is there not a simple command to convert an FsmVar to it's respective type?

I suppose I could brute force the interaction I am looking for by declaring arrays of FsmFloats, FsmInts, FsmStrings, etc, and just ignoring FsmVars altogether, but that hardly seems like an elegant solution.

Hi.
Try looking at the 'Get/Set Fsm Variable' actions as a reference.

Luceid

  • Playmaker Newbie
  • *
  • Posts: 16
Re: Custom Action FsmVar Convert
« Reply #3 on: September 23, 2023, 02:06:31 PM »
I figured it out eventually with some poking from Brokn.

FsmFloats and FsmInts and such just need a .Value to convert them to their native unity type like FsmFloat.Value. I was used to this and didn't realize FsmVars just needed a slightly altered form to work.

FsmVars need that type specified in front of Value in order to be converted directly like:
FsmVar.floatValue

Hope this helps anyone else who might find this later! :)