playMaker

Author Topic: Arraymaker components to String  (Read 2132 times)

KellyRay

  • Full Member
  • ***
  • Posts: 169
    • View Profile
Arraymaker components to String
« on: November 06, 2015, 12:56:29 PM »
I'm trying to write an action that will take string variables from my Array and join them into a string. This is what I have so far but the result ends up as "System.Collections.ArrayList" Any thoughts?

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("ArrayMaker/ArrayList")]
[Tooltip("Joins all elements from a PlayMaker ArrayList Proxy component into a string")]
public class ArrayListJoin : ArrayListActions
{
[ActionSection("Set up")]

[RequiredField]
[Tooltip("The gameObject with the PlayMaker ArrayList Proxy component")]
[CheckForComponent(typeof(PlayMakerArrayListProxy))]
public FsmOwnerDefault gameObject;

[Tooltip("Author defined Reference of the PlayMaker ArrayList Proxy component ( necessary if several component coexists on the same GameObject")]
public FsmString reference;

[ActionSection("Result")]
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmString result;

public bool everyFrame;

public override void Reset()
{
gameObject = null;
reference = null;
result = null;
everyFrame = false;
}


public override void OnEnter()
{
if ( SetUpArrayListProxyPointer(Fsm.GetOwnerDefaultTarget(gameObject),reference.Value) )
JoinArrayList();

if (!everyFrame)
Finish();
}

public override void OnUpdate()
{
if ( SetUpArrayListProxyPointer(Fsm.GetOwnerDefaultTarget(gameObject),reference.Value) )
JoinArrayList();

Finish();
}


public void JoinArrayList()
{
if (! isProxyValid())
return;

result.Value = proxy.arrayList.ToString();
}
}
}

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: Arraymaker components to String
« Reply #1 on: November 07, 2015, 05:29:51 AM »
Hi,
Why dont you get the string then build a new string with the build string action?

KellyRay

  • Full Member
  • ***
  • Posts: 169
    • View Profile
Re: Arraymaker components to String
« Reply #2 on: November 07, 2015, 09:38:34 AM »
In a normal situation this would be the route to go. However, I'm trying to accomplish two things.

I have no way of knowing how many letters will be used to generate the string, could be 2, could be 100. It's based on a players individual input.

Letters are put into the array by players toggling key buttons. I'd like them to be able to take out letters no matter where they put them in the string. So far, the only way I can come up with a solution for this is to store the index number when this letter was put into the array.

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: Arraymaker components to String
« Reply #3 on: November 07, 2015, 09:54:11 AM »
I don't understand. ELI5 me....

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Arraymaker components to String
« Reply #4 on: November 07, 2015, 11:51:51 AM »
Hi,

 unfortunatly, you can't use .ToString() on collections to get the values concatenated into a string. the .ToString() return some info about the collection itself, in our case not very useful...

The simple way is to iterate all items and build the string manually in place of your .ToString().

Bye,

 Jean

KellyRay

  • Full Member
  • ***
  • Posts: 169
    • View Profile
Re: Arraymaker components to String
« Reply #5 on: November 07, 2015, 09:45:16 PM »
Hey Jean,

Thank you for your thoughts. I'm unsure what you meant by iterate. Can you elaborate?

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: Arraymaker components to String
« Reply #6 on: November 08, 2015, 07:04:28 AM »
lol I dont get what you trying to do but maybe this will help http://hutonggames.com/playmakerforum/index.php?topic=7950.0

use the array event system with the above actions..

KellyRay

  • Full Member
  • ***
  • Posts: 169
    • View Profile
Re: Arraymaker components to String
« Reply #7 on: November 08, 2015, 04:26:07 PM »
My struggle with the building string action is that the number of letters in my array will vary every time a player adds and deletes a letter from the word they are attempting to spell.

This is why I'm looking for a single action that can look at the strings (in my case, single letters) in my array, piece them together in order and return a string result every frame that I can check against a dictionary every time a player adds or deletes a letter.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2247
    • View Profile
    • jinxtergames
Re: Arraymaker components to String
« Reply #8 on: November 09, 2015, 12:50:18 AM »
Hi,
i made a sample how to build your string.


but maybe you don't need to use array list...


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Arraymaker components to String
« Reply #9 on: November 09, 2015, 05:30:06 AM »
Hi,

Djaydino example is great, thanks for that!


 Maybe in your case, you could also consider working with a plain string, since you can access a character from a string using "GetSubString", so you have everything the user typed always in regular string, and use buildString to add characters or GetSubstring to remove characters.

Bye,

 Jean

KellyRay

  • Full Member
  • ***
  • Posts: 169
    • View Profile
Re: Arraymaker components to String
« Reply #10 on: November 09, 2015, 07:18:44 AM »
Thank you all for your replies!

Djaydino! That's excellent. Thank you for this. I'll put this together and see how we do!

KellyRay

  • Full Member
  • ***
  • Posts: 169
    • View Profile
Re: Arraymaker components to String
« Reply #11 on: November 09, 2015, 06:39:04 PM »
It worked! Thanks friends! Here's the prototype I've been trying to build!

bit.ly/spellword