playMaker

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

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #15 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.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Action for setting value of GUI textfield?
« Reply #16 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

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #17 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!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Action for setting value of GUI textfield?
« Reply #18 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

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #19 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

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #20 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.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Action for setting value of GUI textfield?
« Reply #21 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

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #22 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.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Action for setting value of GUI textfield?
« Reply #23 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

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #24 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.

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #25 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);
}
}
}
}



Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #26 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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Action for setting value of GUI textfield?
« Reply #27 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

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Action for setting value of GUI textfield?
« Reply #28 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.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Action for setting value of GUI textfield?
« Reply #29 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