playMaker

Author Topic: Script to change values of all variables in Playmaker FSM  (Read 756 times)

Rajeev

  • Playmaker Newbie
  • *
  • Posts: 8
Script to change values of all variables in Playmaker FSM
« on: March 20, 2021, 09:13:07 AM »
Hello,
I need to change the values of several variables in a Playmaker FSM. I am now doing it with this script:
using UnityEngine;
using HutongGames.PlayMaker;

Code: [Select]
public class ChannelNameValues : MonoBehaviour
{
    public PlayMakerFSM fsm;

    public void ResetChannelName()
    {

fsm.FsmVariables.GetFsmString("Step 1 Name").Value = "";
fsm.FsmVariables.GetFsmString("Step 2 Name").Value = "";
fsm.FsmVariables.GetFsmString("Step 3 Name").Value = "";
.
.
.
.
}

}

I need to change the values of about 40 variables in one FSM and I know that this is not the correct way to do it.
Could you please help with an easier method of changing the values  ... something similar to how all the buttons can be set active or inactive by putting them in a list and using "foreach (GameObject obj in objects)
{
        obj.GetComponent<Button>().interactable = false;
    }

"

Thanking you in advance,

Rajeev
« Last Edit: March 21, 2021, 08:43:00 PM by djaydino »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Script to change values of all variables in Playmaker FSM
« Reply #1 on: March 21, 2021, 08:49:03 PM »
Hi.
I updated your post and wrapped the code so its easier to read.

Maybe you could use a string :

Code: [Select]
            int stepCount = 30;

            for (int i = 0; i < stepCount; i++)
            {
                string stepName = "Step " + i + " Name";
                fsm.FsmVariables.GetFsmString(stepName).Value = "";
            }


Rajeev

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Script to change values of all variables in Playmaker FSM
« Reply #2 on: March 24, 2021, 08:52:45 AM »
Hello Sir,

Your code worked perfectly for me. Thank you very much sir. It saved me a heap big amount of work. Sorry for the delay in replying.
Regards,
Rajeev

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Script to change values of all variables in Playmaker FSM
« Reply #3 on: March 24, 2021, 12:38:22 PM »
Hi.
No problem