Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: djaydino on June 06, 2016, 11:39:33 AM

Title: fsm array
Post by: djaydino on June 06, 2016, 11:39:33 AM
Hi,

is it possible to limit this to only string and int array :

Code: [Select]
        [UIHint(UIHint.Variable)]
        [Tooltip("Store the value in a variable.")]
        public FsmArray scoreList;

and can i detect inside the script if it is a int or string?
Title: Re: fsm array
Post by: Alex Chouls on June 06, 2016, 03:55:37 PM
You can set the VariableType using the ArrayEditorAttribute:

Code: [Select]
[ArrayEditor(VariableType.GameObject)]
public FsmArray myGameObjects;

You can get the VariableType stored by an FsmArray using the ElementType property.

Unfortunately an array can only store one variable type.



Title: Re: fsm array
Post by: djaydino on June 06, 2016, 07:13:21 PM
Hi,
I have my action like this :

(http://s33.postimg.org/rhr1gukj3/Capture.jpg)

It works fine, but it looks a bit crowded.

In 'Score Type' and 'Second Type' you can select as string or as int using enum
The lists are arrays.

if possible i would want that the user can only place an array type 'string' or 'int'
in "Score List" and in "Seccond List"
(this way there is less chance having errors)

and then in the script to check if an array type 'string' or 'int' was placed.
(this way 'Score Type' and 'Second Type' are not needed)

I don't have a lot experience with coding yet but this is my code so far :

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2016. All rights reserved.
// Made by Djaydino http://www.jinxtergames.com
// Works with http://dreamlo.com/
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/

using UnityEngine;
using System.Collections;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Web")]
[Tooltip("gets highscores from Dreamlo website and place them in arrays")]
public class DreamloGetScoreToArray : FsmStateAction

    {
public enum ScoreType
{
AsInt,
AsString
}

public enum SecondType
{
AsInt,
AsString
}

public enum SortType
{
ascending,
descending
}

public enum SortBy
{
score,
seconds,
date
}

[RequiredField]
[Tooltip("Place Public Code from the Dreamlo website")]
public FsmString publicCode;


        [UIHint(UIHint.Variable)]
        [Tooltip("Store the value in an array.")]
        public FsmArray nameList;


        [UIHint(UIHint.Variable)]
        [Tooltip("Store the value in an array.")]
        public FsmArray scoreList;

public ScoreType scoreType;


        [UIHint(UIHint.Variable)]
        [Tooltip("Store the value in an array.")]
        public FsmArray secondsList;

public SecondType secondType;


        [UIHint(UIHint.Variable)]
        [Tooltip("Store the value in an array.")]
        public FsmArray textList;


        [UIHint(UIHint.Variable)]
        [Tooltip("Store the value in an array.")]
        public FsmArray dateAndTimeList;

[Tooltip("here you can choose the size of your list for example 10 will give the top 10 scores, leave to none or 0 to get all scores")]
public FsmInt ListSize;

public SortType sortType;
public SortBy sortBy;

public FsmEvent isError;
[Tooltip("Where any errors thrown will be stored. Set this to a variable, or leave it blank.")]

public FsmString errorMessage = "";

private WWW www;


        private Coroutine routine;
private string webUrl;
private string setSaveType;

        public override void Reset()
        {
scoreType = ScoreType.AsInt;
secondType = SecondType.AsInt;
sortType = SortType.descending;
publicCode = null;
ListSize = null;
nameList = null;
scoreList = null;
secondsList = null;
textList = null;
dateAndTimeList = null;
errorMessage = "";
        }


        public override void OnEnter()
        {

switch (sortBy)
{
case SortBy.score:
break;

case SortBy.seconds:
setSaveType = setSaveType + "-seconds";
break;

case SortBy.date:
setSaveType = setSaveType + "-date";
break;
}

switch (sortType)
{
case SortType.descending:
break;

case SortType.ascending:
setSaveType = setSaveType + "-asc";
break;
}
setSaveType = "pipe" + setSaveType;

if (ListSize == null || ListSize.Value == 0)
{
webUrl = "http://dreamlo.com/lb/" + publicCode.Value + "/" + setSaveType;

}
else
{
webUrl = "http://dreamlo.com/lb/" + publicCode.Value + "/" + setSaveType + "/" + ListSize;

}
routine = StartCoroutine(UploadNewHighscore());
        }


        private IEnumerator UploadNewHighscore()
        {
www = new WWW(webUrl);
            yield return www;

if (string.IsNullOrEmpty(www.error))
{
FormatHighscores(www.text);
}
else
{
errorMessage = www.error;
Fsm.Event(isError);
}

        }


void FormatHighscores(string textStream)
{
string[] entries = textStream.Split(new char[] {'\n'}, System.StringSplitOptions.RemoveEmptyEntries);

for (int i = 0; i <entries.Length; i ++)
{

string[] entryInfo = entries[i].Split(new char[] {'|'});
string username = entryInfo[0];
nameList.Resize(nameList.Length+1);
nameList.Set(nameList.Length-1, username);

if (scoreType == ScoreType.AsInt)
{
int scoreInt = int.Parse(entryInfo[1]);
scoreList.Resize(scoreList.Length+1);
scoreList.Set(scoreList.Length-1, scoreInt);
}
else
{
string score = entryInfo[1];
scoreList.Resize(scoreList.Length+1);
scoreList.Set(scoreList.Length-1, score);
}

if (secondType == SecondType.AsInt)
{
int secondsInt = int.Parse(entryInfo[2]);
secondsList.Resize(secondsList.Length+1);
secondsList.Set(secondsList.Length-1, secondsInt);
}
else
{
string seconds = entryInfo[2];
secondsList.Resize(secondsList.Length+1);
secondsList.Set(secondsList.Length-1, seconds);
}

string text = entryInfo[3];
textList.Resize(textList.Length+1);
textList.Set(textList.Length-1, text);

string dateAndTime = entryInfo[4];
dateAndTimeList.Resize(dateAndTimeList.Length+1);
dateAndTimeList.Set(dateAndTimeList.Length-1, dateAndTime);
}

Finish();
}


public override void OnExit()
        {
            StopCoroutine(routine);
        }
}
}
Title: Re: fsm array
Post by: jeanfabre on June 07, 2016, 03:36:01 AM
Hi,

 check StringJoin Action, it forces the type of object for FsmArray.

        [UIHint(UIHint.Variable)]
  --> [ArrayEditor(VariableType.String)]
        [Tooltip("Array of string to join into a single string.")]
        public FsmArray stringArray;


Bye,

 Jean
Title: Re: fsm array
Post by: djaydino on June 07, 2016, 05:36:13 AM
Hi,
Yes but it can have only 1 type.
As i understand that is not possible.

I think i will make it differently with sub selection,
so that when you choose 'as int' you can only place a int array and the same for 'as string'.
Title: Re: fsm array
Post by: jeanfabre on June 08, 2016, 01:51:58 AM
Hi,

Maybe ArrayMaker would be more suitable for this.

 or instead do a getnext or getByIndex action which then save data in a regular Fsm which then lets you pick various types. Like I do with XmlMaker.

 Bye,

 Jean
Title: Re: fsm array
Post by: djaydino on June 08, 2016, 05:55:50 AM
Hi,
I changed my actions a bit and i think they are good now.
Everything is working but i will still test them for a few days,
then i will send them to you so you can add them to
the EcoSystem as a package.

Here is how they look now.
(http://s25.postimg.org/vopygwz67/Capture.jpg)