playMaker

Author Topic: Action for setting value of GUI textfield?  (Read 21473 times)

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Action for setting value of GUI textfield?
« on: April 26, 2011, 07:47:42 AM »
Apologies if this is a stupid question, but is there an action for setting the value contained in a GUI textfield?
I know I can write a script to pass the value, but can you do it with an action?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Action for setting value of GUI textfield?
« Reply #1 on: April 26, 2011, 02:40:19 PM »
A text field always shows the value of a string variable - so make a string variable, set its default value, and assign it to the text field.

Then as the user enters text, the string variable is updated.

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #2 on: April 26, 2011, 04:19:24 PM »
Well that's what I thought but my textfields aren't updating...
Maybe it's because I'm using iGUI...
will try it with some hand rolled GUI elements and see if that changes anything.
Thanks

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #3 on: April 27, 2011, 04:44:48 AM »
Okay, I can create a Playmaker textfield and populate it no problem.
I just don't know enough to figure out how to pass my variable to iGUI's textfield.

These are my two FSM's;

no.1 attached to the iGUI container, which works beautifully...


no.2 attached to the iGUI textfield


GUI interface


Project view


Inspector view of iGUI textfield



Dunno where to go from here... sorry if this is incredibly basic.
--EDIT--
If it helps any:

http://avamstudios.com/content/55-text-field

http://avamstudios.com/iGUI_API/classiGUI_1_1iGUITextfield.html

« Last Edit: April 27, 2011, 04:55:01 AM by Duffdaddy »

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #4 on: April 27, 2011, 05:37:53 PM »
Anyone able to give some thoughts? I'm stuck otherwise...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Action for setting value of GUI textfield?
« Reply #5 on: April 28, 2011, 12:57:49 AM »
Hi,

 Sorry I can not be of any help, cause I don't own iGUi and I am quite positive that it's simply a case of understanding how iGui deal with this to solve the problem. Have you contacted them?

Can you verify that you can indeed do what you want with a conventionnal gui textfield, if so then you sort of know the problem is with iGui integration which I am sure allows to do what you want.

 Bye,

 Jean

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #6 on: April 28, 2011, 01:08:39 AM »
Hi Jean,
Yep can definitely pass variables to Playmaker textfields no problem.
Spoke to Ersan at iGUI/Avam studios and we wondered if we just don't write a script and attach it with Playmaker. Hers what he sent me;

import iGUI;
var namevar1 : String;

var name1 : String;
var textfield1 : iGUITextfield;
private var textfield1LastValue : String;


function Update()

{

 name1 = PlayerPrefs.GetString("Player1 Name");

 namevar1 = name1;
 
  if (textfield1!=null && textfield1LastValue!=textfield1.value)
    {
        PlayerPrefs.SetString("Player1 Name", textfield1.value);

       textfield1LastValue=textfield1.value;
    }

}

}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Action for setting value of GUI textfield?
« Reply #7 on: April 28, 2011, 01:59:41 AM »
Hi,

 Ok, that's a start yes, and could be made into an action. I would suspect you can optimize here and there like not getting the pref every frame but onEnter and only update on keydown and such, but we are speaking about user inputs, so I guess nothing much is happening while this action is live.

I am sure tho, c# would allow for tricks like Delegate and other fanciness. I unfortunately lack of expertize with raw c#.

Do you need this to be translated as an valid playmaker action?

 Bye,

 Jean

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #8 on: April 28, 2011, 03:41:42 AM »
Hey Jean,
You're quite right re the optimisations, onEnter etc would make more sense.
But C# is not my bag either. I'm from a web background so JavaScript works for me.
I did try writing an action but I'm just getting errors, so if you can try that'd be a great help.
Please do translate away!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Action for setting value of GUI textfield?
« Reply #9 on: April 28, 2011, 04:27:17 AM »
Hi,

 Here we go:

I only implement an action to communicate with iGui, no prefs or anything like that since it would defeat the generic nature of actions.

I don't have iGUi yet ( :) ) so make sure the variable type do not throw errors, I tested with a dummy class, so the action is definitely working.

Once you validate this action as working, I will move th code into the proper forum and wiki.

 If you need help to tight this with user prefs, do not hesitate to ask for help.

 Bye,

 Jean
 

 
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{

[ActionCategory("iGUI")]
[Tooltip("Let you control the content of a iGUI textfield, set the content on enter and then inject back user edit")]
public class iGUI_Textfield : FsmStateAction
{
[RequiredField]
public iGUI.iGUITextfield textField;

[UIHint(UIHint.FsmString)]
public FsmString content;

public override void Reset()
{
textField = null;
}

public override void OnEnter()
{

if (textField==null){

Debug.LogWarning("missing iGUI.iGUITextfield");
return;
}

textField.value = content.Value;

}// OnEnter

public override void OnUpdate(){

if (textField==null){
Debug.LogWarning("missing iGUITextfield");
return ;
}

if (textField.value != content.Value){
content.Value = textField.value;
}
}// OnUpdate

}
}
« Last Edit: April 29, 2011, 01:07:58 AM by jeanfabre »

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #10 on: April 28, 2011, 07:02:48 AM »
Brilliant, thanks Jean. I'll test it out when I'm back at work tomorrow.
Will yell if I get stuck. Many thanks!

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #11 on: April 28, 2011, 06:38:34 PM »
Okay, am getting an error. An no action showing in the Action list.

Assets/PlayMaker/Actions/iGUI/iGUI.cs(13,24): error CS0246: The type or namespace name `iGUITextfield' could not be found. Are you missing a using directive or an assembly reference?

I took your script, saved it as .cs file into the actions folder. Is that correct?

--EDIT--
Okay, fixed it. Script referenced iGUITextfield when it needed to be iGUI.iGUITextfield. It works!
« Last Edit: April 28, 2011, 08:03:24 PM by Duffdaddy »

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #12 on: April 28, 2011, 09:39:41 PM »
Okay, dare I ask, but now... how do you repeat this for dropdown lists, switches, buttons, sliders, and radio buttons?

I'm trying to troll through the Playmaker to actions to see I can adapt any, but it's a bit beyond me.
Have sent your action to the guys at iGUI to show them what it takes to integrate with Playmaker.
Hopefully they see it as easy!!!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Action for setting value of GUI textfield?
« Reply #13 on: April 29, 2011, 01:05:52 AM »
Hi,

 Basically you will need to build a custom action for each individual component, because each have their specificity. For the slide, you would deal with a float, for a button, a different system that would instead trigger an event when down and/or maintain a isPressed flag. etc etc.

The other thing: Depending on what you want to achieve, you might simply have iGUI do the work of gathering infos, and in one go communicate it to fsm, instead of fsm dealing with each and every widget on screen.

Could you elaborate on what you intend to do? and we'll take it from there.

Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Action for setting value of GUI textfield?
« Reply #14 on: April 29, 2011, 01:08:41 AM »
Hi,

 Modified the action to work as is using the proper iGUI.iGUITextfield reference.

 Bye,

 Jean