Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: charming_fox 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:
managerPlayMakerFSM.FsmVariables.GetFsmArray("achievementStatus").SaveChanges;
However in Visual Studio this gives me the error:
Error CS0201 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
Here is the full code:
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;
-
Sorry to be a pain but could really do with some advice on this as it's affecting a lot of players, thanks!
-
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?)
-
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.
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:
managerPlayMakerFSM.FsmVariables.GetFsmArray("achievementStatus").SaveChanges;
-
can you show the complete script
As far as I know, you should use something like this :
myFSM.FsmVariables.GetFsmArray("MyArrayName").Set(I, unlocked[i]);
inside the for loop
posibly you could also do :
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++;
}
-
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!
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();
}
}
}
}
-
Actually the second suggestion appears to be working, i'll do more testing before marking as fixed, thank you for your help:
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++;
}