playMaker

Author Topic: Logic Translator  (Read 5001 times)

digimbyte

  • Junior Playmaker
  • **
  • Posts: 52
Logic Translator
« on: January 14, 2013, 11:33:56 PM »
come across another idea, I'd like to mess with something in playmaker
now basically what I'm aiming to make, and hopefully with your help

a translator that checks a string, and outputs a texture from an Array
maybe make it modular so its not always string to texture

the goal is to remove unnecessary states and compress actions needed to compare or translate logic

if there a guide around to building an Action and setup things like every frame and array's?
its basically a fancy IF Action with an array to compare multiple outcomes

idea's, suggestions and criticism is welcome

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15594
  • Official Playmaker Support
Re: Logic Translator
« Reply #1 on: January 15, 2013, 01:11:23 AM »
Hi,

 Yep!

Using ArrayMaker, this is possible, and would work very well.
https://hutonggames.fogbugz.com/default.asp?W715

Using XML and XPath would be even better:
http://hutonggames.com/playmakerforum/index.php?topic=2583.0


Now, the problem with any of the above solution is that PlayMaker doesn't support any internal translation of strings. This would be very useful indeed to flag a string variable or any variable really to be "pre processed" when a fsm needs it.

So currently, you will have to have extra steps manually performed to translate.

Else, you can modify the actions you are using to implement a translation. Actually, if your project has a serious budget, I would even consider writing a framework specifically for that, that you wold use in all your actions, so that querying for a fsm variable, would be done via this framework and it would simply check if there is a translation and return it if present.

something like:

Code: [Select]

string myString = TranslateMaker.TranslateString(MyFsmString.Value);


instead of
Code: [Select]

string myString = myFsmString.Value


If you take this approach, you completly remove the need for any Fsm to do the translation, it's all done within the actions themselves ( and will be a lot more efficient as well)

Now, you will find that sometimes you want a string to be translated, and sometime you don't.. for this, you will have to implement this in your fsm design ( like any other scripting environment), again, if playmaker would implement a translation system, we would likely be given a specific UI to flag a string for translation, within the action UI. That would be so great!

Hopefully in a near future, Playmaker will open it's action UI interface, and this kind of implementation will become possible for use developers, to redesign the string field and add more features in it.


bye,

 Jean

digimbyte

  • Junior Playmaker
  • **
  • Posts: 52
Re: Logic Translator
« Reply #2 on: January 15, 2013, 04:39:21 AM »
framework? ha, all i need it is a cheap way of selecting a draw Text without unnecessary states for each one

basically this, my button Action i made before stores a string value for what map, and a string value for what character/car 
now before the race starts, there's a confirm screen to show what track and what car they will have
I want it to draw a texture based on what the player selected for the map and car string values

from my understanding, to do this normally would require a large amount of states, one per track, and one per vehicle (6^4)

alternately a lot of actions to determine the logic and loop it between 2 states which is just as impractical



how this will work is the input variable is fed into the action, and it goes down a list (array) that you created inside the action, and if it finds any matching string V string value, it will set the output texture variable as the corresponding Texture defined in the array, if no values match, it will apply a default texture


digimbyte

  • Junior Playmaker
  • **
  • Posts: 52
Re: Logic Translator
« Reply #3 on: January 15, 2013, 05:52:19 AM »
so far I have this
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Compares a String Value too the Array and outputs corresponding Texture Variable.")]
public class String2Texture : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmString inputStringVariable;
public FsmTexture outputTexture;
public FsmInt choicesArray;
public bool everyFrame;
public FsmString stringCompareTo;
public FsmTexture listTexture;


public override void Reset()
{
inputStringVariable = null;
outputTexture = null;
choicesArray = 1;
everyFrame = false;
stringCompareTo = "";
}

public override void OnEnter()
{
DoString2Texture();

if (!everyFrame)
{
Finish();
}
}

public override void OnUpdate()
{
DoString2Texture();
}

void DoString2Texture()
{
if (inputStringVariable == null || outputTexture == null) return;

if (inputStringVariable == stringCompareTo)
{
outputTexture = listTexture;
}


}

}
}
Now i need to loop or add more options and its done

i was looking for an Action that has a modular array but i only found it on the GuiLayoout Text Field as "Layout Options"

and seems to be dependent on the text properties and not in the Action at all seen here
text.Value = GUILayout.TextField(text.Value, maxLength.Value, style.Value, LayoutOptions);

solutions?

digimbyte

  • Junior Playmaker
  • **
  • Posts: 52
Re: Logic Translator
« Reply #4 on: January 15, 2013, 06:10:06 AM »
This is what i hope to achieve

digimbyte

  • Junior Playmaker
  • **
  • Posts: 52
Re: Logic Translator
« Reply #5 on: January 15, 2013, 08:05:53 AM »
so here it is, 2 things though and maybe an experienced person can answer or fix this
but, it needs too be "Every Frame" as the update appears to be delayed, it seems to end the frame then update the output
and second thing is lack of "Array List" its manually put in at the moment and I'm not sure how to work around that but i saw a possible solution in a changing GUI theme or something but im lost on how to impliment that

enough of the chit chat, here is my script as im using it
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Compares a String Value too the Array and outputs corresponding Texture Variable.")]
public class String2Texture : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmString inputStringVariable;
public FsmTexture outputTexture;
//[ActionSection("Default")]
//public FsmTexture defaultTexture;
public bool everyFrame; //Glitchy, seems to have a delay when False
public FsmInt numberOfChoices;
//Currently the 'Number of Choices' does not work so 4 choices are listed until that is updated.
[ActionSection("Choices")]
public FsmString stringCompareTo;
public FsmTexture listTexture;
[ActionSection("")]
public FsmString stringCompareTo2;
public FsmTexture listTexture2;
[ActionSection("")]
public FsmString stringCompareTo3;
public FsmTexture listTexture3;
[ActionSection("")]
public FsmString stringCompareTo4;
public FsmTexture listTexture4;


public override void Reset()
{
inputStringVariable = null;
outputTexture = null;
numberOfChoices = 0;
everyFrame = true;
}

public override void OnEnter()
{
DoString2Texture();


}

public override void OnUpdate()
{
DoString2Texture();

if (!everyFrame)
{
Finish();
}
}

void DoString2Texture()
{
//if (inputStringVariable == null) return;

if (inputStringVariable.Value == stringCompareTo.Value)
{
outputTexture.Value = listTexture.Value;
}

if (inputStringVariable.Value == stringCompareTo2.Value)
{
outputTexture.Value = listTexture2.Value;
}

if (inputStringVariable.Value == stringCompareTo3.Value)
{
outputTexture.Value = listTexture3.Value;
}

if (inputStringVariable.Value == stringCompareTo4.Value)
{
outputTexture.Value = listTexture4.Value;
}


}

}
}