Playmaker Forum

PlayMaker Feedback => Action Requests => Topic started by: KellyRay on November 06, 2015, 02:56:29 PM

Title: Arraymaker components to String
Post by: KellyRay on November 06, 2015, 02: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();
}
}
}
Title: Re: Arraymaker components to String
Post by: dudebxl on November 07, 2015, 07:29:51 AM
Hi,
Why dont you get the string then build a new string with the build string action?
Title: Re: Arraymaker components to String
Post by: KellyRay on November 07, 2015, 11: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.
Title: Re: Arraymaker components to String
Post by: dudebxl on November 07, 2015, 11:54:11 AM
I don't understand. ELI5 me....
Title: Re: Arraymaker components to String
Post by: jeanfabre on November 07, 2015, 01:51:51 PM
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
Title: Re: Arraymaker components to String
Post by: KellyRay on November 07, 2015, 11:45:16 PM
Hey Jean,

Thank you for your thoughts. I'm unsure what you meant by iterate. Can you elaborate?
Title: Re: Arraymaker components to String
Post by: dudebxl on November 08, 2015, 09: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..
Title: Re: Arraymaker components to String
Post by: KellyRay on November 08, 2015, 06: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.
Title: Re: Arraymaker components to String
Post by: djaydino on November 09, 2015, 02:50:18 AM
Hi,
i made a sample how to build your string.


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

Title: Re: Arraymaker components to String
Post by: jeanfabre on November 09, 2015, 07: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
Title: Re: Arraymaker components to String
Post by: KellyRay on November 09, 2015, 09: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!
Title: Re: Arraymaker components to String
Post by: KellyRay on November 09, 2015, 08:39:04 PM
It worked! Thanks friends! Here's the prototype I've been trying to build!

bit.ly/spellword