playMaker

Author Topic: Button with Variable string (Closed)  (Read 4381 times)

digimbyte

  • Junior Playmaker
  • **
  • Posts: 52
Button with Variable string (Closed)
« on: January 14, 2013, 12:05:09 AM »
So i've been trying to make a Menu system when a user clicks on a button, it would set a variable then change states, the only work around, was to have a transition on every button, but what if you didn't want a transition or what if you have a number of selections?

I needed to add some way to force a variable, so i merged the "set string" into the "GUI Button"

simply click on the gear for "GUI Button" and select EDIT, then copy paste this over the original
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

using UnityEngine;
using System.Collections.Generic;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GUI)]
[Tooltip("GUI button. Sends an Event when pressed. Optionally store the button state in a Bool Variable.")]
public class GUIButton : GUIContentAction
{
public FsmEvent sendEvent;
[UIHint(UIHint.Variable)]
public FsmBool storeButtonState;
//
public FsmString stringVariable;
public FsmString stringValue;
//

public override void Reset()
{
base.Reset();
sendEvent = null;
storeButtonState = null;
style = "Button";

}

public override void OnGUI()
{
base.OnGUI();

bool pressed = false;


if (GUI.Button(rect, content, style.Value))
{
Fsm.Event(sendEvent);
stringVariable.Value = stringValue.Value;
pressed = true;

}

if (storeButtonState != null)
{
storeButtonState.Value = pressed;
}
}
}
}

The reason I'm posting the code is so others who maybe more experienced in modifying it, can update it without uploading unnecessary files and versions
I really did this blind folded knowing nothing about the format of how to make actions, I just hope i got it right
« Last Edit: January 15, 2013, 06:53:49 PM by digimbyte »

digimbyte

  • Junior Playmaker
  • **
  • Posts: 52
Re: Button with Variable string
« Reply #1 on: January 14, 2013, 07:46:42 AM »
Updated/Fixed

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Button with Variable string
« Reply #2 on: January 15, 2013, 12:31:28 AM »
Hi,

 It's great you are getting into making actions! few things tho:

-- If you create custom action, try to name them uniquely so that users downloading this do not get errors because of the duplicate name. so for example you could name it GUIButton2 or something even more meaningfull... :)

 I am not sure I am following. Where do you set stringValue?

Using the regular I GUIButton, I can assign a variable already to the string, so I can change dynamically the string. Could you explain a use case?

I think you are missing on the concept of using several Fsm to achieve one feature. Here Your button would send a global event that is not implemented in its own fsm, thus it will not leave this state at all. The other fsm receives the event, process it, and can change back the string value by using "set fsm string" back to the Fsm featuring the button.

 does that make sense?

bye,

 Jean

digimbyte

  • Junior Playmaker
  • **
  • Posts: 52
Re: Button with Variable string
« Reply #3 on: January 15, 2013, 08:44:02 AM »
wait what? I'm afraid that makes no sense at all, sleepy jean?

I don't want to name it anything 'meaningful' as its supposed to be an update GUIButton
the issue is that currently buttons are only used for moving between state and if you have multiple buttons to change several values, you don't want a state for every button output and using the boolean "pressed" is a joke

this adds a String Variable output allowing when pressed to set the value of a string local or global when the button is pressed with no need for unnecessary states or checks

in other words, its a light weight "set String" implemented on a button, I would suppose it could set Int as well but that's not to much trouble to add
« Last Edit: January 15, 2013, 08:45:34 AM by digimbyte »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Button with Variable string
« Reply #4 on: January 15, 2013, 10:07:25 AM »
Hi,

 monkees rocks :) especially their choregraphy... how did you guessed I was a day time dreamer tho  :D

 Ok, I see. I would however still put the energy into making it into a proper fsm, and put that button in a prefab, then you get the same results. But yes, now I get what you want to do, perfectly fine of course.

bye,

 Jean