playMaker

Author Topic: Get Any Key Store Result as String  (Read 18380 times)

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Get Any Key Store Result as String
« on: July 25, 2011, 03:29:48 PM »
Modification to the Get any Key Action
Allows you to store the result of which button was pressed in a string variable

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

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Input)]
[Tooltip("Sends an Event when the user hits any Key or Mouse Button.")]
public class AnyKeyStoreString : FsmStateAction
{
[RequiredField]
public FsmEvent sendEvent;
[UIHint(UIHint.Variable)]
public FsmString storeResult;

public override void Reset()
{
sendEvent = null;
storeResult = null;
}

public override void OnUpdate()
{
storeResult.Value = Input.inputString;
if (Input.anyKeyDown)
Fsm.Event(sendEvent);
}
}
}

FractalCore

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 100
Re: Get Any Key Store Result as String
« Reply #1 on: October 04, 2013, 04:26:16 AM »
I just got round to trying this. Want to make some kind of text input system. But this action didn't seem to work.

It just works like the AnyKey action it's based on (doesn't store a string, just triggers the event).
« Last Edit: October 04, 2013, 04:57:17 AM by FractalCore »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Any Key Store Result as String
« Reply #2 on: October 04, 2013, 08:44:30 AM »
Hi,

 it works for me, I just tried.

bye,

 Jean

FractalCore

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 100
Re: Get Any Key Store Result as String
« Reply #3 on: October 04, 2013, 09:18:50 PM »
Then I must be either missing something or I misinterpreted the use of this action.

You can see from these pictures my resulting built string is ---. I assumed it would be h-h-h- since that's the key I pressed.

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: Get Any Key Store Result as String
« Reply #4 on: October 04, 2013, 09:57:44 PM »
Correct me if im wrong jean, but build string requires you give it Arrays of strings for each element, not actual string variables.

so that's why they are blank in the output.


justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: Get Any Key Store Result as String
« Reply #5 on: October 04, 2013, 10:21:32 PM »
Hrrm seems i'm getting the same error as @FractalCore now.  Its not saving the string anymore.

I wrote this a long time ago, did something change in playmaker that could be breaking it Jean?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Any Key Store Result as String
« Reply #6 on: October 07, 2013, 02:45:10 AM »
Hi,

It's all working wheel here. I'll build a small example. Please bump me towards the end of the week.

bye,

 Jean

MABManZ

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 125
    • MABManZ.com
Re: Get Any Key Store Result as String
« Reply #7 on: October 08, 2013, 05:34:32 AM »
FYI this is the same issue I was having in the action request forum, but kinda gave up for the time being and wanted to come back later. Glad to see I'm not going crazy

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Any Key Store Result as String
« Reply #8 on: October 08, 2013, 07:11:22 AM »
Hi,

 Here is a working sample.

 Let me know if this is what you need.

Bye,

 Jean

FractalCore

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 100
Re: Get Any Key Store Result as String
« Reply #9 on: October 08, 2013, 07:56:46 AM »
Thanks.

Using your demo, single key presses still didn't work. So I mashed a whole lot of keys at once and got some results. Then went back and tried my own scene again.

Sure enough mashing many keys at once will register one or two keys. A single press does nothing. The same results in your scene and mine, so I'm using it right.

Weird. It's as if it's taking the input and then clearing it again in a single frame, too fast to see. And many simultaneous keys clog it up and the last few pressed will be kept. That's my novice explanation.

I got the same results in Playmaker 1.6.0 and 1.7.5 and in Unity 3.5.7, 4.0.0, and 4.2.0, all in Windows 7 64Bit.
« Last Edit: October 08, 2013, 08:09:32 AM by FractalCore »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Any Key Store Result as String
« Reply #10 on: October 08, 2013, 08:05:20 AM »
Hi,

 there is a serious issue here, cause, this scene works perfectly here. everytime I press a key, it works. I can type my name just fine.

 Can you make a screencast of what you are experiencing?

you are likely set up right, something may be wrong in your OS or within Unity install on your computer or certain kinds of setup.

 what keyboard do you have? what computer?

Bye,

 Jean

FractalCore

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 100
Re: Get Any Key Store Result as String
« Reply #11 on: October 08, 2013, 08:08:59 AM »
Tested on two different machines, one with a really old keyboard (PS/2) and the other with a CMStorm Quickfire gaming keyboard (USB2) I bought on Saturday.
« Last Edit: October 08, 2013, 08:40:39 AM by FractalCore »

FractalCore

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 100
Re: Get Any Key Store Result as String
« Reply #12 on: October 08, 2013, 08:13:33 AM »
Ok, I just built and ran it. It works that way. Just not in the editor.

Any idea why that might happen?
« Last Edit: October 08, 2013, 08:16:04 AM by FractalCore »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Any Key Store Result as String
« Reply #13 on: October 08, 2013, 02:49:57 PM »
Hi,

 no idea... but something is definitly wrong. I am on mac so maybe the unity has a glitch on windows. Maybe other will perhaps confirm this.

bye,

 Jean

MABManZ

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 125
    • MABManZ.com
Re: Get Any Key Store Result as String
« Reply #14 on: October 09, 2013, 03:34:44 AM »
Ran your sample scene and the same problem occurs (clears the key within 1 frame), but I'm on the same setup as FractalCore (Windows 7 64-bit), sorry don't have a Mac to try unfortunately.