playMaker

Author Topic: [Solved] Convert String to Int - Error  (Read 1414 times)

createasaurus

  • Full Member
  • ***
  • Posts: 145
    • View Profile
[Solved] Convert String to Int - Error
« on: January 09, 2018, 01:54:06 PM »
I'm asking the player to type in numerical information in the uGui input field.  Things like age and height.

Then I use the Convert String to Int Action.  And I do different things based on the age and height.

However, when the player types non numerical information... like "DGF" and I use the Convert String to Int Action, I get an error.

Code: [Select]
FormatException: Input string was not in the correct format
System.Int32.Parse (System.String s) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Int32.cs:629)
HutongGames.PlayMaker.Actions.ConvertStringToInt.DoConvertStringToInt () (at Assets/PlayMaker/Actions/ConvertStringToInt.cs:46)
HutongGames.PlayMaker.Actions.ConvertStringToInt.OnEnter () (at Assets/PlayMaker/Actions/ConvertStringToInt.cs:33)
HutongGames.PlayMaker.FsmState.ActivateActions (Int32 startIndex) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:199)
HutongGames.PlayMaker.FsmState.OnEnter () (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:169)
HutongGames.PlayMaker.Fsm.EnterState (HutongGames.PlayMaker.FsmState state) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2670)
HutongGames.PlayMaker.Fsm.SwitchState (HutongGames.PlayMaker.FsmState toState) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2628)
HutongGames.PlayMaker.Fsm.UpdateStateChanges () (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2556)
HutongGames.PlayMaker.Fsm.UpdateState (HutongGames.PlayMaker.FsmState state) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2686)
HutongGames.PlayMaker.Fsm.Update () (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1920)
PlayMakerFSM.Update () (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:532)

The good news is the errors are only in my console and it dose not seem to crash the game in my limited testing.  However, should I worry for extended play?  This game will be left on for days (museum instillation).

Because I cannot control what the player types, I'm struggling how to solve this.
Is there a command that can help me, or an "Identify if String is an Int" Action?

Thank you kindly for your thoughts.
« Last Edit: January 10, 2018, 08:55:40 AM by createasaurus »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5082
    • View Profile
    • jinxtergames
Re: Convert String to Int - Error
« Reply #1 on: January 09, 2018, 02:46:18 PM »
Hi,
Maybe you can check when the player pressed a key if it is equal to a digit.

Have an array (string) and place the number 0 on index (element 0) 1 on index 1...and so on until 9.

Then after each key pressed loop thru the array and compare the string, if it is a number (for example 6) it will send a Equal event and if none match you can place a message to the player that it is not a number.

You can use for example 'build string' if you need multiple digits (10, 100, 1000,...)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15318
  • Official Playmaker Support
    • View Profile
Re: Convert String to Int - Error
« Reply #2 on: January 09, 2018, 11:55:57 PM »
Hi,

Yes, this action assumes you are passing indeed an int as a string and it will fire an error if you don't, and that should not affect the gameplay nor the game.

If you want I can make a new custom action that will convert a string to int but without throwing an error and instead fire an event in the case of a failure? would that be better for your case?

 Bye,

 Jean

createasaurus

  • Full Member
  • ***
  • Posts: 145
    • View Profile
Re: Convert String to Int - Error
« Reply #3 on: January 10, 2018, 08:53:08 AM »
Quote
that should not affect the gameplay nor the game.
This is the most important!!  My main concern was that these errors may add up and at... lets say 1000, and it would say "too many errors" and crash the game.

Everything is good then!!

I do not want to trouble you with a custom action then, as this does not seem to effect the user experience.  Thank you so much!!
« Last Edit: January 10, 2018, 08:55:26 AM by createasaurus »