playMaker

Author Topic: Copying an array via script to an FSM array variable  (Read 825 times)

charming_fox

  • Junior Playmaker
  • **
  • Posts: 62
Copying an array via script to an FSM array variable
« on: October 13, 2023, 09:30:43 AM »
Hi, i'm trying to copy variables from an array in a script into an FSM's array variable. Although it kinda works there seems to be some issues with it updating reliably... After reading another post I tried adding the line:

Code: [Select]
managerPlayMakerFSM.FsmVariables.GetFsmArray("achievementStatus").SaveChanges;
However in Visual Studio this gives me the error:

Code: [Select]
Error CS0201 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
Here is the full code:

Code: [Select]
public void CheckAllAchievementStatus()
        {
            //loop through the array 'unlocked' and set each bool entry to the result from the steam query and total them up in a lovely int
            totalUnlocked = 0;
            managerPlayMakerFSM.FsmVariables.GetFsmBool("checkComplete").Value = false;

            for (int i = 0; i < unlocked.Length; i++)
            {
                unlocked[i] = ach[i].IsAchieved;
                achievementStatusFsmArray.boolValues = unlocked;
                if (unlocked[i])
                {
                    totalUnlocked++;
                }
            }
       
            //copy the array to the PlaymakerFSM array
            achievementStatusFsmArray.boolValues = unlocked;
            managerPlayMakerFSM.FsmVariables.GetFsmArray("achievementStatus").SaveChanges;
            managerPlayMakerFSM.FsmVariables.GetFsmInt("achievementsUnlocked").Value = totalUnlocked;
            managerPlayMakerFSM.FsmVariables.GetFsmBool("checkComplete").Value = true;

charming_fox

  • Junior Playmaker
  • **
  • Posts: 62
Re: Copying an array via script to an FSM array variable
« Reply #1 on: October 14, 2023, 08:45:11 AM »
Sorry to be a pain but could really do with some advice on this as it's affecting a lot of players, thanks!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Copying an array via script to an FSM array variable
« Reply #2 on: October 16, 2023, 08:41:25 AM »
 achievementStatusFsmArray.boolValues = unlocked;

this line looks wrong to me

unlocked should probably be unlocked

also the achievementStatusFsmArray.boolValues
i think is wrong (what array is it referencing to?)

charming_fox

  • Junior Playmaker
  • **
  • Posts: 62
Re: Copying an array via script to an FSM array variable
« Reply #3 on: October 17, 2023, 08:24:00 AM »
achievementStatusFsmArray.boolValues = unlocked;

this line looks wrong to me

unlocked should probably be unlocked

also the achievementStatusFsmArray.boolValues
i think is wrong (what array is it referencing to?)


Hi, thanks for helping, with the existing code the array is successfully copied, it's just that the copied array contents don't show up in the FSM's array unless I inspect the variables in the PlayMaker/Variables window during runtime in the editor.

Code: [Select]
achievementStatusFsmArray.boolValues = unlocked[i];

As you suggested I tried the above line but this errors ('i' does not exist in the current context), I think the original code is correct afaik.

It's this line that is erroring for me but I don't know why:
Code: [Select]
managerPlayMakerFSM.FsmVariables.GetFsmArray("achievementStatus").SaveChanges;




djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Copying an array via script to an FSM array variable
« Reply #4 on: October 17, 2023, 02:16:57 PM »
can you show the complete script

As far as I know, you should use something like this :
Code: [Select]
myFSM.FsmVariables.GetFsmArray("MyArrayName").Set(I, unlocked[i]);
inside the for loop

posibly you could also do :

Code: [Select]
            var myFsmArray = fsmDebug.FsmVariables.GetFsmArray("MyArray");

            for (int i = 0; i < unlocked.Length; i++)
            {
                myFsmArray.Set(i, ach[i].IsAchieved);

                if(ach[i].IsAchieved) totalUnlocked++;
            }



charming_fox

  • Junior Playmaker
  • **
  • Posts: 62
Re: Copying an array via script to an FSM array variable
« Reply #5 on: October 18, 2023, 11:15:48 AM »
Thanks again for trying to help, full script is below, with the suggested changes I get:IndexOutOfRangeException: Index was outside the bounds of the array.

Still stumped!

Code: [Select]
using HeathenEngineering.SteamworksIntegration;
using HeathenEngineering.SteamworksIntegration.API;
using Steamworks;
using UnityEngine;
using HutongGames.PlayMaker;

namespace HeathenEngineering.SteamworksIntegration
{

    public class SteamAchievementsManager : MonoBehaviour
    {
        public AchievementObject[] ach;
        public int achIndex;
        public bool[] unlocked;
        private int totalUnlocked;
        private FsmArray achievementStatusFsmArray;
        private PlayMakerFSM managerPlayMakerFSM;

        // Start is called before the first frame update

        private void Start()
        {
            //get the fsm component and the array
            managerPlayMakerFSM = gameObject.GetComponent<PlayMakerFSM>();
            achievementStatusFsmArray = managerPlayMakerFSM.FsmVariables.GetFsmArray("achievementStatus");

        }

        // Update is called once per frame
        public void UnlockAchievement()
        {
            achIndex = managerPlayMakerFSM.FsmVariables.GetFsmInt("achievementIndex").Value;
            Debug.Log(achIndex);
            ach[achIndex].Unlock();
            API.StatsAndAchievements.Client.StoreStats();
            CheckAllAchievementStatus();
        }

        public void CheckAllAchievementStatus()
        {
            //loop through the array 'unlocked' and set each bool entry to the result from the steam query and total them up in a lovely int
            totalUnlocked = 0;
            managerPlayMakerFSM.FsmVariables.GetFsmBool("checkComplete").Value = false;
            Debug.Log("starting ach check");

            for (int i = 0; i < unlocked.Length; i++)
            {
                unlocked[i] = ach[i].IsAchieved;
                Debug.Log(unlocked[i]);
                Debug.Log(ach[i].IsAchieved);
               
                if (unlocked[i])
                {
                    totalUnlocked++;
                    Debug.Log("unlocked is " + unlocked[i]);
                    managerPlayMakerFSM.FsmVariables.GetFsmArray("achievementStatus").Set(i, unlocked[i]);
                    achievementStatusFsmArray.boolValues = unlocked;
                }
            }
            //achievementStatusFsmArray.boolValues = unlocked;
            //managerPlayMakerFSM.FsmVariables.GetFsmArray("achievementStatus").SaveChanges;
            managerPlayMakerFSM.FsmVariables.GetFsmInt("achievementsUnlocked").Value = totalUnlocked;
            managerPlayMakerFSM.FsmVariables.GetFsmBool("checkComplete").Value = true;

           
        }

        public void ClearAllAchievements()
        {
            for (int i = 0; i < unlocked.Length; i++)
            {
                ach[i].ClearAchievement();
                API.StatsAndAchievements.Client.StoreStats();
                CheckAllAchievementStatus();
            }
        }
    }
}


charming_fox

  • Junior Playmaker
  • **
  • Posts: 62
Re: Copying an array via script to an FSM array variable
« Reply #6 on: October 18, 2023, 11:26:59 AM »
Actually the second suggestion appears to be working, i'll do more testing before marking as fixed, thank you for your help:
Code: [Select]
var myFsmArray = fsmDebug.FsmVariables.GetFsmArray("MyArray");

            for (int i = 0; i < unlocked.Length; i++)
            {
                myFsmArray.Set(i, ach[i].IsAchieved);

                if(ach[i].IsAchieved) totalUnlocked++;
            }

florencepugh

  • Playmaker Newbie
  • *
  • Posts: 1
Re: Copying an array via script to an FSM array variable
« Reply #7 on: March 18, 2024, 01:04:53 AM »
You can use SaveChanges Method following these steps below: Store the result of `GetFsmArray` in a variable:
Code: [Select]
FsmArray achievementStatusFsmArray = managerPlayMakerFSM.FsmVariables.GetFsmArray("achievementStatus");
Update the array values:
Code: [Select]
achievementStatusFsmArray.boolValues = unlocked;
Call `SaveChanges` on the `achievementStatusFsmArray` variable:
Code: [Select]
achievementStatusFsmArray.SaveChanges();

ramane

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Copying an array via script to an FSM array variable
« Reply #8 on: March 19, 2024, 02:48:27 AM »
You can use SaveChanges Method following these steps below: snow rider 3d
Store the result of `GetFsmArray` in a variable:
Code: [Select]
FsmArray achievementStatusFsmArray = managerPlayMakerFSM.FsmVariables.GetFsmArray("achievementStatus");
Update the array values:
Code: [Select]
achievementStatusFsmArray.boolValues = unlocked;
Call `SaveChanges` on the `achievementStatusFsmArray` variable:
Code: [Select]
achievementStatusFsmArray.SaveChanges();
That;s great. it worked. Thank you!