Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Duffdaddy on April 26, 2011, 07:47:42 AM

Title: Action for setting value of GUI textfield?
Post by: Duffdaddy 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?
Title: Re: Action for setting value of GUI textfield?
Post by: Alex Chouls 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.
Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy 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
Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy 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...
(http://selfmanage.neogine.com/public/static_imgs/fsm1.jpg)

no.2 attached to the iGUI textfield
(http://selfmanage.neogine.com/public/static_imgs/fsm2.jpg)

GUI interface
(http://selfmanage.neogine.com/public/static_imgs/interface.jpg)

Project view
(http://selfmanage.neogine.com/public/static_imgs/project.jpg)

Inspector view of iGUI textfield
(http://selfmanage.neogine.com/public/static_imgs/inspector.jpg)


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

Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy on April 27, 2011, 05:37:53 PM
Anyone able to give some thoughts? I'm stuck otherwise...
Title: Re: Action for setting value of GUI textfield?
Post by: jeanfabre 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
Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy 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;
    }

}

}
Title: Re: Action for setting value of GUI textfield?
Post by: jeanfabre 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
Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy 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!
Title: Re: Action for setting value of GUI textfield?
Post by: jeanfabre 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

}
}
Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy 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!
Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy 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!
Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy 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!!!
Title: Re: Action for setting value of GUI textfield?
Post by: jeanfabre 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
Title: Re: Action for setting value of GUI textfield?
Post by: jeanfabre on April 29, 2011, 01:08:41 AM
Hi,

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

 Bye,

 Jean
Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy on April 29, 2011, 05:44:25 AM
Hi,
Thanks for updating the action.
Well I've tried to have another go at writing an action for a drop down list, but I just don't know enough to call the right classes, attributes, etc.

As for what am wanting to do, well there are a variety of operations to take place.
There's a user preference pane with textfields, text areas, dropdown lists, and radio buttons which need to both have their values set and retrieved.
Then there's another settings pane, with iphone style switches (for wifi/3G), sliders for location update frequency and accuracy, etc. I'm using Prime 31's location plugin for those aspects to gather the data.
Lastly there are forward and back buttons on each pane as well as a save and reset button.

Sooooo, pretty much everything but the kitchen sink.
I guess I've made a rod for my own back as I've decided to prototype my interface with iGUI, and the integrate it with Playmaker.
Title: Re: Action for setting value of GUI textfield?
Post by: jeanfabre on April 29, 2011, 05:56:37 AM
Hi,

 I think it's just a matter of finding the right balance, and after all it make total sense to be willing to use iGUI and playmaker if you don't want to script much. The thing is bridges need to be built.

 I think this is an interesting combination. Maybe I should get in contact directly with iGUI and see if they can help me build these bridges. Meanwhile could you elaborate your need for the dropdown? Do you need to set the content from fsm? or do you simply need to get alerted when the user has selected an item?

 I studied a bit the api from iGUI and it seems that it could be all done event without custom actions if for example in the files generated by iGUI you plug playmaker and send events to fsm. This is also something to consider and could be an easier way out for you to get on with it. Does that make sense to you?


 Bye,

 Jean
Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy on April 29, 2011, 06:49:23 AM
Hi,
Yes I think you're right about it being a balance. To do enough and no more than needed to keep it simple.

Re; the dropdown, yes I do need it to set content at the launch of the app. I need the PlayerPrefs to sustain themselves between app launches and that data populates the user prefs pane, so the dropdown has be as it was the last time the app was launched.

I take your point with regard to using iGUI to drive events instead of creating custom actions to populate discrete FSM. I hadn't considered that. Not sure it'd work... Here's why:
My original intent was, for the PlayerPrefs at least, is to have a simple FSM attached to each field in the user prefs pane which;

a.) populated the field/s or dropdown with data from PlayerPrefs whenever the pane was activated on the apps launch. This happens only once each launch.

b.) another state in the same FSM would then essentially site idle until the user focus's on a field and then exits it. It then takes the data in the field, saves it back to PlayerPrefs and refreshes the field with the new data.

Not sure you could do that thru events only, but you may have a better idea than me with what's possible.

If you want to ask the guys at Avam Studios re what they're up to. They've indicated they're interested in integrating with Playmaker - it makes sense as they both share the same audiences. Email Ersan, that's who I've been dealing with. Try info AT avamstudios DOT com.

Thanks for all your help!
Title: Re: Action for setting value of GUI textfield?
Post by: jeanfabre on April 29, 2011, 09:34:03 AM
Hi,

 Yes, I contacted them and he said playmaker integration is coming up in the coming days. Excellent!

re events. basically you want to react on a user selection, so event is perfect for this, you don't need to watch anything, you simply wait for the event to trigger and act only then.

 Anyway, let's wait what iGUi come up with, I am sure it will solve your issues.

 Bye,

 Jean
Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy on April 29, 2011, 03:37:45 PM
Hi,
Ah, right! That's great news re: the guys at iGUI.
And I like your idea with using the events to trigger data capture etc. Will make use of that idea on another project I'm working on that doesn't employ iGUI.
Many thanks
Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy on May 15, 2011, 10:16:42 PM
Hey Jean,
You about? I just noticed that your handy iGUI action doesn't seem to want transition to another action, or state.
How do I work around that? I want it to cascade to another action, but it just seems to stop on itself.
Any ideas? I tried adding a finish() to the OnUpdate part of the script but it doesn't have affect.
Title: Re: Action for setting value of GUI textfield?
Post by: jeanfabre on May 16, 2011, 12:43:51 AM
Hi,

 Yes, if you move to another state then you need to plug it somehow back when you need that behvaior again. But I don't see this as as problem. during the next set of states and action you will perform, you have stored the latest content of that field, so you are ok. Simply reach a state where you again check live for the content when needed.

 ELSE. Make a specific fsm that deals with that gui text field,  sending events when the user presses ok on the form related to this gui text field and react only then.

 Or maybe you could explain the process at stake, maybe it's not conventional or has a twist to it.

 Bye,

 Jean
Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy on May 16, 2011, 05:05:43 AM
Hi Jean
Yea I'd figured that I can save it from another state, but I wanted to do it a bit like some of the apple apps that save data dynamically. Basically as you edit fields the data is saved as you change focus.
But I might just settle for a "save" or "update" button and be done with it. Not elegant, but functional.

Title: Re: Action for setting value of GUI textfield?
Post by: jeanfabre on May 16, 2011, 05:19:14 AM
Well, you don't need to settle for that.

 Simply make the live update of the texfield a FSM on its own. And you have the answer to this, use the focus variable to know when to save. The solution you adopted at start to save as you type the value in the pref is still something completly feasible, you just need to define a state where you save the data and go to that state when the user edited the field.

For example, the action I wrote could be expanded to trigger an event when the user has changed the content. You then catch that event either in the same fsm or in another and save that value in the pref. If you are in the same fsm, don't forget to come back to the state that watch the field content.

 Try some more. If you are having problems, I'll make a working example of live update to the prefs using the custom action of this thread.

 Bye,

 Jean
Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy on May 16, 2011, 05:56:30 AM
Thanks Jean, t'was thinking about duping your action and seeing if I could implement a broadcast event.
Will try and follow your suggested approach. Makes sense and a heck of a lot more elegant than a button.
Thanks. Let you know how I get on.
Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy on May 19, 2011, 07:05:26 PM
Okay, have had a go at this, and it was working, but now... not so much.

Hacked around with existing Playmaker events and your translated event from iGUI and this is what I got. See attached.

The events for Textfields work fine, but the events for the Dropdown appear to kinda work, but,... setting the variable OnUpdate seems to get over written with the fields default or empty value (in this case Int variable) when I launch app.
So in this case, the default selectIndex for the dropdown is -1 which sets the dropdown to read 'Select'. If I select an option and the selectIndex value is 0, the OnUpdate does its job and updates the variable and fires an event which then saves the variable to a PlayerPref.
But, when I stop the play button in Unity, then hit it again to start the app again the the variable is supposed reinstated from PlayerPrefs. But what happens instead is the default Int variable value gets popped in there instead - so in this case '0' for an Int.

It's probably my crap understanding and hacking together of actions.

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

using UnityEngine;
using System.Collections.Generic;

namespace HutongGames.PlayMaker.Actions
{

[ActionCategory("iGUI")]
[Tooltip("Let you set the content of a iGUI Dropdown OnUpdate and then inject back on user edit and send an event")]
public class iGUiDropdownSetOnUpdateSendEvent : FsmStateAction
{
[RequiredField]
public iGUI.iGUIDropDownList DropDownlist;
[UIHint(UIHint.FsmInt)]
public FsmInt content;
[RequiredField]
public FsmString broadcastEvent;
[Tooltip("Optionally specify a game object to broadcast the event to all FSMs on that game object.")]
public FsmGameObject gameObject;
[Tooltip("Broadcast to all FSMs on the game object's children.")]
public FsmBool sendToChildren;
public FsmBool excludeSelf;
public bool everyFrame;

public override void Reset()
{
DropDownlist = null;
broadcastEvent = null;
sendToChildren = false;
excludeSelf = false;
}

public override void OnUpdate(){

if (DropDownlist==null){
Debug.LogWarning("missing iGUIDropDownList");
return;
}

if (DropDownlist.selectedIndex != content.Value){
content.Value = DropDownlist.selectedIndex;
BroadcastToAll();
}
}// OnUpdate

void BroadcastToAll()
{
// copy the list in case broadcast event changes Fsm.FsmList

var fsmList = new List<Fsm>(Fsm.FsmList);

//Debug.Log("BroadcastToAll");
foreach (var fsm in fsmList)
{
if (excludeSelf.Value && fsm == Fsm)
{
continue;
}

//Debug.Log("to: " + fsm.Name);
fsm.Event(broadcastEvent.Value);
}
}
}
}


Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy on May 22, 2011, 06:04:25 PM
Have had a further attempt to get this working, but no luck.
Can anyone shed any light on why my variable is being drawn from the default value rather than the player prefs. See my post immediately above.
Cheers
Title: Re: Action for setting value of GUI textfield?
Post by: jeanfabre on May 23, 2011, 05:13:01 AM
Sorry,

 Lacking time currently to properly look at this and build a working example of what you are trying to achieve. Hopefully towards the end of the week.

 bye,

 Jean
Title: Re: Action for setting value of GUI textfield?
Post by: Duffdaddy on May 23, 2011, 05:22:22 PM
How ironic, I make that post last night, and blow me over, the blimmin thing starts working!!!

Be good if you could have you look at it though, in case it's a fluke.
However, it does make me suspect a bit about the Playmakers reliability re: variables.
Is there any caching going on that could be causing the issues I'm seeing?

It's as though the variables are cached and not being flushed with every stop/play inside Unity.
Title: Re: Action for setting value of GUI textfield?
Post by: jeanfabre on May 24, 2011, 05:39:59 AM
Hi,

 Glad you got it working.

never had problems with variables. Remember you are playing with user prefs, so if you have bug in your process, you might just inject the wrong value to your variables at the wrong time.

 Bye,

 Jean