playMaker

Author Topic: Calculator with Playmaker  (Read 3489 times)

Andrew

  • Playmaker Newbie
  • *
  • Posts: 4
Calculator with Playmaker
« on: September 05, 2016, 04:37:36 AM »
Playmaker newbie here!

I'm trying to make a sort of calculator using Playmaker. I'm sure it is possible, but I can't seem to get even multiplying working..

I can't seem to get anything to output as a string. I've set up 'Width' and 'Length' Global Int Variables, used Int Operator and set Integer 1 as 'Width' and Integer 2 as 'Length', then set to multiply and store the result in another Global Int Variable called 'AreaResult'.

I then set up an Int to String converter which I convert 'AreaResult' to Global String Variable 'AreaString'.

Lastly I drag the 'Text' of which I was the string displayed on into the State and Set Property to Text > String and the Set Value to 'AreaString' variable.

I think this is all right, but I think it just doesn't get the values from 'Length' or 'Width' to calculate. For the user input I have added 'InputField' UI in the Canvas, and added 'Set Int Value' and selected 'Width' and 'Length' for each one and left the Value as '0' as I thought the user would be able to determine this.. But this is where I am stuck.. and I know I must be doing something wrong, or using the wrong Action.

How can I get the user to enter the Int Value so it can be stored in a variable to then be calculated? Do I need an Update state?

Thanks, I appreciate any help with this!  ;D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Calculator with Playmaker
« Reply #1 on: September 05, 2016, 04:40:59 AM »
Hi,

 that's a good questions and something I'll turn into a sample for the Ecosystem.

 Can you give me this week so that I can work on it? You'll then have a fully working example to demonstrate this.

 Meanwhile, I'll explain the principle so that you can keep at it ( solving design patterns your self is always better for learning :) )

-- at the time of calculation, you are going to get both fields, and convert them into floats, you don't need global variables, it can be all done inside a single FSM, using local variables.

-- once you have the two floats, you move to another state ( using FINISH), and do a "float operator" action, feeding both floats, and returning the result into a third float variable.

-- you then convert back the result from a float to a string, and inject that string into the result UI label in your Interface.

Does that make sense?
 
Bye,

 Jean

Andrew

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Calculator with Playmaker
« Reply #2 on: September 05, 2016, 03:48:06 PM »
Hi Jean,

Thanks for your reply - a sample would be great!

I'm still not quite sure I understand though..
As for the two input fields, do I need FSM's on those? With 'Set Int Variable'?

Also for the Calculating FSM, I think I'm doing it wrong, but ill upload some screenshots to show you what I have put so far..

State 1


State 2


Was I supposed to 'Get Property' from both of those fields first?

I guess State 1 seems kind of pointless to me, but I have tried many different ways but can't get it going.. :P

EDIT:

I have figured it out, and able to do it all within one single state.
Not sure why I found this so difficult..



Thanks for your help!
« Last Edit: September 05, 2016, 08:47:24 PM by Andrew »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Calculator with Playmaker
« Reply #3 on: September 06, 2016, 02:56:48 AM »
Hi,

 I have created a full set of actions and proxies for the new UI system, don't use "get/set Property" for UI elements, instead use my actions.

I think you also need to watch as many videos on HutongGames youtube channel to get acquainted with the various patterns and principle behind PlayMaker. then you can start to design your own logics and all.

Keep at it, the difficulties you are facing now will seem very little when you'll gain experience and practice, so don't worry about the early difficulties.

 Bye,

 Jean


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Calculator with Playmaker
« Reply #4 on: September 15, 2016, 05:22:20 AM »
Hi,

 ok, here we go, I wrapped up a new uGui Sample on the Ecosystem, to give you an example on a simple calculator.





It' making use of a new action I created to simplify things with UI, that gets a InputField directly as an int or a float, making this kind of logic very quick to implement.

 note also the tab navigation between fields, it's from a component available in uGui Proxy Full Package called "InputNavigation".

 Let me know if you have questions, the fsm is very simple, so you should be good.

 Bye,

 Jean