playMaker

Author Topic: FSMArray to Array  (Read 1312 times)

Arnoob

  • Junior Playmaker
  • **
  • Posts: 63
    • View Profile
FSMArray to Array
« on: November 23, 2017, 07:08:48 AM »
 >:(Hello everyone!

In order to create some new actions that I need, I have to convert a FSMArray to a Standard array.

I know how to do it with standard Playmaker's values, using the "FSMValue.Value" trick. However I have no clue about how to do it for arrays.

I already tried multiple things, and the closest I could come to was something like : "Color32[] array = ArrayPlaymaker.Values;" but it couldn't compile, telling me that it couldn't "implicitly convert type `object[]' to `UnityEngine.Color32[]'".

Could someone help show me what line should I type in order to convert the FSMArray to a UnityEngine Color Array?
« Last Edit: November 26, 2017, 06:50:12 PM by Arnoob »

Arnoob

  • Junior Playmaker
  • **
  • Posts: 63
    • View Profile
Re: FSMArray to Array
« Reply #1 on: November 24, 2017, 12:28:23 PM »
I hate to bump my own thread, but I really need help about that.

The closest thing I found was in an other thread, it was a method to convert an Array to a FSMArray... Saddly that's the inverse of what I am looking for, and I didn't manage to revert it.

Quote
to produce an array of gameobjects, you can try this

    [ArrayEditor(VariableType.GameObject)]
      public FsmArray pmArray;

assuming you have the gameobjects on a variable called myGameobjects which is a simple GameObject[], the try this:
   
    pmArray.Resize(myGameobjects.Length);  // set the playmaker array size
    for (int i = 0; i < myGameobjects.Length; i++) //loop gameobjects
        pmArray.Set(i, myGameobjects);   // use the Set method to add to PM array

I hope someone can help me on this one. I really don't know how to notify that my playmaker array is of type "Color32" (or anything else by the way)...

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4620
    • View Profile
    • jinxtergames
Re: FSMArray to Array [UNRESOLVED]
« Reply #2 on: November 26, 2017, 05:00:00 PM »
Hi.
I am not sure if you can copy a fsmarray directly to an array

but the code below can do it

Code: [Select]
        for (int i = 0; i < theFSM.FsmVariables.GetFsmArray("fsmArray").Length; i++)
        {
            Color arrayItem = (Color)theFSM.FsmVariables.GetFsmArray("fsmArray").Get(i);
            // Place into list or array here if needed
            Debug.Log(arrayItem);
        }

Arnoob

  • Junior Playmaker
  • **
  • Posts: 63
    • View Profile
Re: FSMArray to Array [UNRESOLVED]
« Reply #3 on: November 26, 2017, 06:49:49 PM »
Thank you a lot for your response djandino!

Just to be clear here, the script you showed me needs to be put into a separate script that I put on the Gameobject that has the FSM with the array on it, not in an action itself, is that right?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4620
    • View Profile
    • jinxtergames
Re: FSMArray to Array
« Reply #4 on: November 27, 2017, 04:53:45 PM »
Hi.
No. it can be in an editor script or on any object in the scene.

But you need to get the "theFsm"

Depending on how you want to use this you can get it in different ways.

on an object, you can use :
Code: [Select]
public PlayMakerFSM theFSM;and drop the fsm in it.

in an editor script :
Code: [Select]
theFSM = theGameObject.GetComponent<PlayMakerFSM>();