playMaker

Author Topic: [Solved]Copying Array from script to FSM Array.  (Read 2099 times)

serenefox

  • Full Member
  • ***
  • Posts: 135
    • Serenefox Games
[Solved]Copying Array from script to FSM Array.
« on: January 16, 2019, 04:15:26 AM »
Hi community,

I am trying to write a bridge of sorts between Dungen and Playmaker assets.

I am trying to copy the array values from my script to the fsm array variable so I can work with it in playmaker. For some reason I can't figure out why the array values wont load into the playmaker fsm I have assigned in the inspector. Any help would be appreciated, Thanks!

Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DunGen;
using HutongGames.PlayMaker;

public class GetDoorPrefabsInTile : MonoBehaviour
{
    public FsmArray pfsmArray;
    public PlayMakerFSM DoorFunctionalityFSM;
    public string nameOfArrayToWorkWith;
    public Tile tile;
    private GameObject[] PlaymakerFSMArray;

    private void Start()
    {
        pfsmArray = DoorFunctionalityFSM.FsmVariables.GetFsmArray(nameOfArrayToWorkWith);
    }

    public void FindDoorPrefabs()
    {
        // Get the tile that you want somehow
        GameObject[] tempArray;
        int doorIndex = 0;

        int Doorwaycount = tile.Placement.AllDoorways.Count;
       
        tempArray = new GameObject[Doorwaycount];
        // Loop through each used doorway in the tile - used doorways are those that are connected to other tiles
        foreach (var doorway in tile.Placement.UsedDoorways)
        {
            // Only one door prefab is spawed per doorway-pair so it might be on this doorway, or it might be on the other
            GameObject doorPrefab = (doorway.UsedDoorPrefab != null) ? doorway.UsedDoorPrefab : doorway.ConnectedDoorway.UsedDoorPrefab;

            if (doorway.UsedDoorPrefab != null)
            {
                tempArray[doorIndex] = doorPrefab;
                doorIndex++;
            }
           
        }
        //doorIndex = 0;
        pfsmArray.Values = tempArray;
    }

}
« Last Edit: January 16, 2019, 07:05:38 PM by serenefox »
Most Recent Published Games:
Juicy Theater - Android

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Copying Array from script to FSM Array.
« Reply #1 on: January 16, 2019, 07:12:53 AM »
Hi.
I can't test right now, but i do know you need to do something like fsmArray.saveChanges

Code: [Select]
fsmTarget.FsmVariables.GetFsmArray(arrayName.Value).SaveChanges();

serenefox

  • Full Member
  • ***
  • Posts: 135
    • Serenefox Games
Re: Copying Array from script to FSM Array.
« Reply #2 on: January 16, 2019, 02:57:44 PM »
Hello djaydino,

I tried adding your suggestion to my code but I am get this error:

Code: [Select]
Nested arrays are not supported yet!
UnityEngine.Debug:LogError(Object)
HutongGames.PlayMaker.FsmArray:Load(Int32) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmVariables/FsmArray.cs:251)
HutongGames.PlayMaker.FsmArray:SaveChanges() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmVariables/FsmArray.cs:339)
GetDoorPrefabsInTile:FindDoorPrefabs() (at Assets/_GameAssets/Scripts/GetDoorPrefabsInTile.cs:44)
System.Reflection.MethodBase:Invoke(Object, Object[])
HutongGames.PlayMaker.Actions.CallMethod:DoMethodCall() (at Assets/PlayMaker/Actions/ScriptControl/CallMethod.cs:98)
HutongGames.PlayMaker.Actions.CallMethod:OnEnter() (at Assets/PlayMaker/Actions/ScriptControl/CallMethod.cs:64)
HutongGames.PlayMaker.FsmState:ActivateActions(Int32) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:205)
HutongGames.PlayMaker.FsmState:OnEnter() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:175)
HutongGames.PlayMaker.Fsm:EnterState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2768)
HutongGames.PlayMaker.Fsm:SwitchState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2715)
HutongGames.PlayMaker.Fsm:UpdateStateChanges() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2643)
HutongGames.PlayMaker.Fsm:Start() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1926)
PlayMakerFSM:Start() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:548)


Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DunGen;
using HutongGames.PlayMaker;

public class GetDoorPrefabsInTile : MonoBehaviour
{
    public FsmArray pfsmArray;
    public PlayMakerFSM DoorFunctionalityFSM;
    public string nameOfArrayToWorkWith;
    public Tile tile;
    private GameObject[] PlaymakerFSMArray;

    private void Start()
    {
        pfsmArray = DoorFunctionalityFSM.FsmVariables.GetFsmArray(nameOfArrayToWorkWith);
    }

    public void FindDoorPrefabs()
    {
        GameObject[] tempArray;
        int doorIndex = 0;

        int Doorwaycount = tile.Placement.UsedDoorways.Count;

        tempArray = new GameObject[Doorwaycount];
        // Loop through each used doorway in the tile - used doorways are those that are connected to other tiles
        foreach (var doorway in tile.Placement.UsedDoorways)
        {
            // Only one door prefab is spawed per doorway-pair so it might be on this doorway, or it might be on the other
            GameObject doorPrefab = (doorway.UsedDoorPrefab != null) ? doorway.UsedDoorPrefab : doorway.ConnectedDoorway.UsedDoorPrefab;

            if (doorway.UsedDoorPrefab != null)
            {
                tempArray[doorIndex] = doorPrefab;
                doorIndex++;
            }

        }
        //doorIndex = 0;
        pfsmArray.Values = tempArray;
        pfsmArray.SaveChanges();
    }

}
Most Recent Published Games:
Juicy Theater - Android

serenefox

  • Full Member
  • ***
  • Posts: 135
    • Serenefox Games
Re: Copying Array from script to FSM Array.
« Reply #3 on: January 16, 2019, 07:05:16 PM »
Hey djaydino,

I finally got it to work. Thanks for your help. Apparently I am not able to assign the array value on start and I had to use the full line where I was saving them:

Code: [Select]
DoorFunctionalityFSM.FsmVariables.GetFsmArray(nameOfArrayToWorkWith).SaveValues();
Most Recent Published Games:
Juicy Theater - Android