Playmaker Forum

PlayMaker Updates & Downloads => Official Action Updates => Topic started by: Alex Chouls on May 17, 2014, 12:58:57 PM

Title: Conditional Expression Action (BETA)
Post by: Alex Chouls on May 17, 2014, 12:58:57 PM
First a huge thanks to Lea Hayes for doing all the hard work on this action!!

The Conditional Expression action lets you evaluate an expression as true or false and store the result or send events based on the result.

You can use named FSM variables in the expression. If the variable name has spaces use this format: $(variable name with spaces)

Anyway, have a play with it and post feedback. This should be considered a beta release. The final version will be included in the next update.

And again, a huge thanks to Lea Hayes for contributing this action to Playmaker!
Lea makes the excellent Rotorz Tile System: http://u3d.as/content/rotorz-limited/rotorz-tile-system/2UU
He also has a great blog: http://leahayes.wordpress.com/
And Rotorz blog: http://rotorz.com/blog/

EDIT: Updated to v1.1:
- Made text field bigger.
- Added Refresh button.

Some sort of auto-refresh is preferable, but it will need editor support, so for now there is a manual refresh button for when you add/remove/edit variables and then return to the action.

EDIT: Fixed build error.
Title: Re: Conditional Expression Action (BETA)
Post by: TrentSterling on May 17, 2014, 01:17:22 PM
 :o oWoow

EDIT: I like seeing programmer centric actions. Being able to evaluate little bits of code like this might not be strictly 'playmaker style', but it would really cut down on action clutter and it's quite awesome!

And I'm also happy I avoid spaces in my variable names now :)
Title: Re: Conditional Expression Action (BETA)
Post by: Lane on May 17, 2014, 01:19:42 PM
Awesome!  ;D

1) First thing I would suggest is a bigger space to type the expression =) Like the comment action field has.

2) Also during the editor mode you have to actually click and change the expression field if you want it to re-evaluate any variable changes you've made in the editor.
Title: Re: Conditional Expression Action (BETA)
Post by: jeanfabre on May 19, 2014, 09:35:11 AM
Hi,

 Very cool, I would see straight away a lot of thing to expand on this.

 expression should allow the return of more than a bool, floats, ints, string, etc. I feel it could be frustrating to get such a convenient action to just return bools, but I am not sure how it's made under the hood, so it may be not really possible to expand on this.

also, I tried to use a string variable but I think the value will always evaluate to true, I think it should evaluate string for "1", "true" "false", empty or with content and return true or false on these cases.

Or, maybe double check what variables are use and warn the user about unsupported variable types within this expression

Bye,

 Jean
Title: Re: Conditional Expression Action (BETA)
Post by: Alex Chouls on May 19, 2014, 04:22:23 PM
Awesome!  ;D

1) First thing I would suggest is a bigger space to type the expression =) Like the comment action field has.

2) Also during the editor mode you have to actually click and change the expression field if you want it to re-evaluate any variable changes you've made in the editor.

Great feedback! I've uploaded v1.1 above...
Title: Re: Conditional Expression Action (BETA)
Post by: Alex Chouls on May 19, 2014, 04:25:42 PM
Quote
expression should allow the return of more than a bool, floats, ints, string, etc. I feel it could be frustrating to get such a convenient action to just return bools, but I am not sure how it's made under the hood, so it may be not really possible to expand on this.

I'm looking into this - maybe Lea will help out :)

But I think it will be a separate action, e.g.,: Math Expression.

Quote
also, I tried to use a string variable but I think the value will always evaluate to true, I think it should evaluate string for "1", "true" "false", empty or with content and return true or false on these cases.

Or, maybe double check what variables are use and warn the user about unsupported variable types within this expression

Good point. This should be possible...
Title: Re: Conditional Expression Action (BETA)
Post by: Lane on May 21, 2014, 07:35:22 AM
Build errors! Woo!

This is for Standalone. It also happened on the previous version.

The line compiles apparently, so I assume its not being picky about formatting. (edit, actually it fails without any actions being used, so its in the dll)
Title: Re: Conditional Expression Action (BETA)
Post by: Alex Chouls on May 21, 2014, 11:52:33 AM
Thanks! I'll fix this in the next release...
Title: Re: Conditional Expression Action (BETA)
Post by: Alex Chouls on May 21, 2014, 12:40:44 PM
Uploaded a new version that should fix the build error.
Title: Re: Conditional Expression Action (BETA)
Post by: Lane on May 21, 2014, 01:28:50 PM
Works great, I can't seem to break anything else on it. Going to start using it on future iterations of the flight AI and might find more out then. Bundling lots of conditions into a bool value is going to be so useful for AI, especially with a delegate fsm just reading contextual data and flipping bools, then the behavior fsm responding to those flags async.... *hnnnngggghh*..

Only other thing I notice that could be a small nuisance is toggling the expression box to a variable and back will null the field, so you lose anything you might have typed in. Really just a minor inconvenience on the rare occasion that you hit the button accidentally.
Title: Re: Conditional Expression Action (BETA)
Post by: Alex Chouls on May 21, 2014, 01:34:51 PM
Great! Please also keep an eye on performance as you use this. I'll build a stress test to compare expressions to regular actions, but I'd also like real world tests...
Title: Re: Conditional Expression Action (BETA)
Post by: Red on July 29, 2014, 12:39:51 PM
This is fantastic! Many, many thanks to the developer!

One question... What if I wanted to get the "X" value of a vector2 variable (or vector3 variable) to test? Would it be something to simply extract and place into a float or would there be something like a "Vector2.x" or "Vector2[1]" kinda thing?

edit: using "Vector2.x", "Vector2[1]" and "Vector2{1}" all produce errors... So, can I get it to fetch the values within the expression itself or is this something that I'd do with an action external to this function? If the suggestion to me is to extract them separately, I'd love to suggest the ability to work with vectors (both 2 and 3)
Title: Re: Conditional Expression Action (BETA)
Post by: gsmetzer on August 06, 2014, 12:50:27 PM
I also agree with Jean that it would really expand functionality if we had different variable outputs.   I would love a similar math action where I could do things like, example:

(myFloat1 + myFloat2)/myInteger  = myOutput float


everyframe

Does that make sense? 
It could really cut down on the clicks and extra actions
Title: Re: Conditional Expression Action (BETA)
Post by: Yanifska on August 07, 2014, 08:24:33 AM
That would definitly help a lot !
+1 for math action
Title: Re: Conditional Expression Action (BETA)
Post by: Red on August 25, 2014, 12:04:26 PM
I think I may have stumbled on a potential bug here... Not sure if this is with the expression system itself or if it's with the prefab management thing but here goes the details.

I've noticed that sometimes the conditional expression doesn't always update the proper expression in the field when working with it as a prefab and adjusting or changing it. The expression shows the right one but it behaves like a previous change/edit/etc... The workaround I found was to simply remove that action and re-add it and put the expression in again which makes me think that there may be a bit of confusion in how the expressions are stashed and handled. It's not something I can easily reproduce but if I do come across it again I'll do what I can to save the information so that I can maybe post a package link.

Still, I can't say that this sours me on this system... It's fantastic! But as with it being beta I can totally understand how there may be some bugs to work out or that kinda thing (and it may not even be with the system itself but rather the prefab management thing that was (is?) an issue.)
Title: Re: Conditional Expression Action (BETA)
Post by: Red on August 25, 2014, 12:13:33 PM
One thing that I think could bear mentioning here is that this action is quite helpful in making complex actions simpler.

For example... I have it working in the camera control system where I want to make the camera move if the player is outside of a certain range. Previously I'd have to set up a system that uses the float operators, bool tests, that kinda thing and then do a test... And since some of those work best as a sequential action that meant I'd have to make that system cycle through every frame/unit-of-time.

This changes... Now I just get the position of the player and camera every frame and in the expression itself I have "player-pos > (camera-pos + padding)" for each direction. Saves me time and really makes for a much cleaner state.

So, I guess this is me singing praise for Lea's work. Thank you!
Title: Re: Conditional Expression Action (BETA)
Post by: emperor1412 on September 20, 2014, 01:26:27 PM
Hi, the plugin is cool, I suggest that the next update would allow to access global FSM variables
Title: Re: Conditional Expression Action (BETA)
Post by: gamedivision on October 09, 2014, 10:31:07 AM
Could someone just expand on the functionality how does it get access to variables just by naming them,and are we talking about the variables that are only attached to that specific FSM

Thanks
Title: Re: Conditional Expression Action (BETA)
Post by: gamedivision on October 11, 2014, 05:56:39 AM
Could this be used to remove trigger boxes based on camera distance,like if cam-Pos = to collider then remove otherwise show
Title: Re: Conditional Expression Action (BETA)
Post by: play_edu on April 16, 2015, 08:39:37 AM
I tryed with this action It's Work fine in pc but not Working on Mobile.
i'm i missing something?

Title: Re: Conditional Expression Action (BETA)
Post by: centaurianmudpig on August 04, 2015, 09:03:40 AM
This is very useful. It would be great if it could work with global variables.

I hope this hasn't been abandoned since it is undocumented and not implemented in the PlayMaker package.
Title: Re: Conditional Expression Action (BETA)
Post by: Tremzoff on June 20, 2016, 11:17:00 AM
I have a question concerning Conditional Expression Action and strings. How should the Expression look for checking wether a string matches or not?

string == "something" ?

Is there any documentation for the Expressions syntax and/or operators?

Title: Re: Conditional Expression Action (BETA)
Post by: Alex Chouls on June 20, 2016, 04:19:41 PM
Yes, put the value in quotes, e.g., name == "Bob"

There's some documentation here:
https://hutonggames.fogbugz.com/default.asp?W1226

It could probably use a bit more detail in terms of syntax and operators allowed.
But the result field gives you feedback as you edit the expression which should help...

EDIT: BTW this action is now included with Playmaker, so you should use that version.
Title: Re: Conditional Expression Action (BETA)
Post by: Tremzoff on June 21, 2016, 04:18:13 AM
@Alex Chouls

Thanks a lot! And looks like the online documentation got a little extended ;-)

Regards
Title: Re: Conditional Expression Action (BETA)
Post by: Alex Chouls on June 21, 2016, 11:14:27 AM
Yeah, I added the string example :)
Title: Re: Conditional Expression Action (BETA)
Post by: Alatriste on January 16, 2017, 01:29:15 PM
Can you call for global variables? If so, how the expression would be?

Thanks!
Title: Re: Conditional Expression Action (BETA)
Post by: jeanfabre on January 17, 2017, 12:48:46 AM
Hi,

 Good questions! I have pinged Alex on this. We'll know soon.


 Bye,

 Jean
Title: Re: Conditional Expression Action (BETA)
Post by: marv on February 03, 2017, 07:46:47 AM
It would be grand if this action could be updated with an "Error Event" similar to the "xml select single node" action for when the content of the string variable used to store the condition is invalid.

I'm using the conditional expression action to test conditions read out of xml files and if there's a mistake somewhere in one of them (which happens easily) the fsm simply stops working instead of allowing me to output an error message.

This would help greatly to weed out those errors without bogging down the whole system.
Title: Re: Conditional Expression Action (BETA)
Post by: marv on February 20, 2017, 08:28:54 AM
Okay, I found another problem with this action that kind of makes it not viable anymore for what I actually wanted to use it for.

When using a string variable to change the actual expression (not the values of the variables used) in runtime it just doesn't update properly and continues to use the initial value of the string variable set in the editor.

Edit: it doesn't work properly when you change the value of the string in the editor either, even with the "refresh" button... I can't believe I hadn't noticed that earlier.

Any chance of someone picking work on this action up again? This is actually pretty major for me since I started redesigning "availability checks" of events and other things around this action... probably should've tested it more thoroughly... for some reason I didn't notice this for quite some while.

edit2: Well, turns out when used in a template it works properly the first time around, but afterwards it uses the string value from the first run... and I'd only done a test run with one "item", saw it worked and then started implementing it everywhere.
Title: Re: Conditional Expression Action (BETA)
Post by: jeanfabre on February 22, 2017, 01:28:56 AM
Hi,

 and if you reenter the state where you have the expression, does it work then?

I would raise a bug report on this too anyway. It would be good to change expression at runtime I agree.

 Bye,

 Jean
Title: Re: Conditional Expression Action (BETA)
Post by: marv on February 22, 2017, 06:44:10 AM
Hi,

thanks for the reply Jean. I just set up a small test FSM (see attachement, ignore the error log, those are unrelated) to show the behavior.

Using a bool variable called "Bool":
a) Bool variable value is true, Expression string is initially empty.

-> it will check correctly once after the expression has been changed from empty to "Bool==false" and return "false". It will then just continue to return "false" in a loop even though the expression has changed to "Bool==true" and it should return "true"

b) Bool variable value is true, initial Expression string is "Bool==true"

-> it will continually return "true" in a loop, even though the start state set the Expression string to "Bool==false" and false should be returned.

Similarly if you set the Expression string in the editor initially to "Bool==true", open the state and click "Refresh" on the action it will return "true". If you then change the value of the string to "Bool==false", go back to the state and click "Refresh" it will show the changed expression but still return "true".

Edit: Bug report submitted (I hope this is something that can be resolved quickly, it's causing me a major headache right now)

cheers

Title: Re: Conditional Expression Action (BETA)
Post by: jeanfabre on March 01, 2017, 12:53:16 AM
Hi,

 I have raised the case internally, hopefully this is something feasible.

 Bye,

 Jean
Title: Re: Conditional Expression Action (BETA)
Post by: Alex Chouls on March 13, 2017, 02:50:18 PM
Please try the attached version of the action.
It should recompile the expression if it changes.
Title: Re: Conditional Expression Action (BETA)
Post by: marv on March 14, 2017, 07:53:30 AM
Heya, thanks for taking a look at this.

I've tried it and got the following compiler error:

Assets/PlayMaker Utils/Wizards/LinkerWizard/Editor/LinkerEditorChecks.cs(17,66): error CS0433: The imported type `PlayMaker.ConditionalExpression.ConditionalExpression' is defined multiple times

Can only be resolved by deleting the ConditionalExpressionAction.cs from this package after which the original one still remains but can't actually be located anywhere in the project. :/

When trying to locate it:
Couldn't find Action Script: PlayMaker.ConditionalExpression.ConditionalExpression
UnityEngine.Debug:LogError(Object)
HutongGames.PlayMakerEditor.ActionScripts:PingAssetByType(Object) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/ActionScripts.cs:123)
UnityEditor.GenericMenu:CatchMenu(Object, String[], Int32)


I also tried it in another project I set up only a couple of days ago with the same result.

Edit: the "couldn't find action script" error occurs before trying to replace the action as well, btw. so it probably wasn't caused by it but rather is connected to the reason why the replacing doesn't work. (I hope I'm not just being dense here... I'm not a programmer myself, so I'm just fishing :D )
Title: Re: Conditional Expression Action (BETA)
Post by: jeanfabre on March 15, 2017, 02:59:27 AM
Hi,

 Yes, this package is not the right one, So it won't install properly.

 I did test on the latest beta and I can confirm that both global variables and expression update are now working, so watch for the next PlayMaker update on the Asset Store, it will be available then.

 Bye,

 Jean
Title: Re: Conditional Expression Action (BETA)
Post by: jeanfabre on March 15, 2017, 08:23:03 AM
Hi,

 Can you download it again from the post above, it's now featuring the proper dll.

 Bye,

 Jean
Title: Re: Conditional Expression Action (BETA)
Post by: marv on March 15, 2017, 12:22:18 PM
Yes, it works now. Thank you guys so much. :)
Title: Re: Conditional Expression Action (BETA)
Post by: Alatriste on May 08, 2017, 11:19:59 AM
Hi,

 Yes, this package is not the right one, So it won't install properly.

 I did test on the latest beta and I can confirm that both global variables and expression update are now working, so watch for the next PlayMaker update on the Asset Store, it will be available then.

 Bye,

 Jean

How do you call for the global variable? Could you write down an example for the expression, please? :)
Title: Re: Conditional Expression Action (BETA)
Post by: Fat Pug Studio on May 11, 2017, 06:28:24 AM
Yeah, that interests me too, didn't download the latest version to check if any instructions are included though.
Title: Re: Conditional Expression Action (BETA)
Post by: jeanfabre on May 15, 2017, 05:13:10 AM
Hi,

 you reference the global variable just as you do for the local variables, it's been fixed, you need to the latest version of PlayMaker.

 Bye,

 Jean
Title: Re: Conditional Expression Action (BETA)
Post by: Fat Pug Studio on May 15, 2017, 10:25:27 AM
Awesome  8)
Title: Re: Conditional Expression Action (BETA)
Post by: Broken Stylus on August 06, 2018, 01:48:25 PM
Rise from your grave!

Hi!
How does one test for non-single element FsmVars like vectors 2/3, quaternions, enums or stuff like that?
Title: Re: Conditional Expression Action (BETA)
Post by: jeanfabre on September 18, 2018, 09:49:00 AM
Hi,

 Yeah, it would be great to be able to access more complex variables indeed. Can you report this using our bug report so that we can keep track of this request, I think it's a good improvement to make.

 Bye,

 Jean