PlayMaker Help & Tips > PlayMaker Help
Copying an array via script to an FSM array variable
charming_fox:
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: ---managerPlayMakerFSM.FsmVariables.GetFsmArray("achievementStatus").SaveChanges;
--- End code ---
However in Visual Studio this gives me the error:
--- Code: ---Error CS0201 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
--- End code ---
Here is the full code:
--- 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;
--- End code ---
charming_fox:
Sorry to be a pain but could really do with some advice on this as it's affecting a lot of players, thanks!
djaydino:
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:
--- Quote from: djaydino 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?)
--- End quote ---
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: --- achievementStatusFsmArray.boolValues = unlocked[i];
--- End code ---
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: ---managerPlayMakerFSM.FsmVariables.GetFsmArray("achievementStatus").SaveChanges;
--- End code ---
djaydino:
can you show the complete script
As far as I know, you should use something like this :
--- Code: ---myFSM.FsmVariables.GetFsmArray("MyArrayName").Set(I, unlocked[i]);
--- End code ---
inside the for loop
posibly you could also do :
--- Code: --- 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++;
}
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version