playMaker

Author Topic: Float Compare [SOLVED]  (Read 2952 times)

sascham

  • Playmaker Newbie
  • *
  • Posts: 9
Float Compare [SOLVED]
« on: December 04, 2011, 02:30:15 AM »
Hi,
I want to trigger an event based on the x & y value.
The float compare only allows me to compare 1 value at the time and to use x value to trigger and in a 2nd state check the y value would not work as X maybe by that time is "wrong" again.

What i try to accomplish is to trigger an event based on an object location x,y

Thanks
« Last Edit: December 13, 2011, 04:43:40 PM by alexchouls »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Float Compare
« Reply #1 on: December 05, 2011, 12:37:21 AM »
Hi,

 I am not sure if moving from one fsm to the other si done within the same frame or not, I would think so tho. I'll let Alex comment on this.

you have several different ways to adress this problem.

One way would be ( in one single state)

1: check if x is equal to your x trigger value, and store the result in a bool ( x_flag)
2: check if y is equal to your y trigger value, and store the result in a bool (y_flag)
3: check that x_flag and y_flag are both true ( using "bool all true" action)

That way you do all your check in one state and you can rest assure x and y are checked at the same time.


A second way ( this is fun :) )

instead of triggering a success event, turn it up side down and exit when it doesn't match.

1: if x is not equal to your x trigger value, transit to a "FAIL" event
        -- if the next action is processed, that means x is equal to the x trigger value
2: if y is not equal to your y trigger value, transit to the same "FAIL" event
       -- if the next action is processed, that means x is equal to the x trigger value
3: have the "finish" transition do its job ( which means x and y are on the spot)


A Third way ( I promess, the last one!)  would be to write a vector equal custom action, that triggers events when equal or when not equal ( basically, comparing x, y and z values ). This would be  good way if your check happens in many places during your game loop, or don't want to create too much variables and checks for this task. If you want this and can't code it, simply shout, and I'll make that custom action for you.



 Bye,

 Jean


Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Float Compare
« Reply #2 on: December 11, 2011, 11:42:17 AM »
Moving to the second state happens in the same Update, so x will not have changed.

Events are processed immediately, during the Update. This lets you string a whole bunch of states together in a single update to build more complex algorithms.