Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Rajeev on March 20, 2021, 09:13:07 AM

Title: Script to change values of all variables in Playmaker FSM
Post by: Rajeev 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
Title: Re: Script to change values of all variables in Playmaker FSM
Post by: djaydino 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 = "";
            }

Title: Re: Script to change values of all variables in Playmaker FSM
Post by: Rajeev 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
Title: Re: Script to change values of all variables in Playmaker FSM
Post by: djaydino on March 24, 2021, 12:38:22 PM
Hi.
No problem