-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ExpressionCondition and ExpressionConditionEditor #31
base: master
Are you sure you want to change the base?
Conversation
01132c6
to
759e514
Compare
Just figure out a way to support trigger in expression without syntax like It works by extracting parameter names from expression with the help of regex. |
I'm not in favor of this commit. This could bring bugs and this reduce the potential of the ExpressionCondition. The intent is nice, but for documentation purposes, it's rather easy to say that the expression parsing is compatible with the Expression class, and that there is a trigger variable. Expression accepts valid GDScript syntax and some functions (like
I don't think regex is the right way to parse scripts. I rather use a shorter trigger variable name, like We could use a custom function too that makes sure no params are overridden. We could use a base instance with the method The image condition could be read as |
759e514
to
e7c8ab6
Compare
3fa8ca2
to
24cafa2
Compare
24cafa2
to
3b635b6
Compare
Yes and no. Trigger are the culprit here. They are specifically distinct as the fact that they only exist for a cycle with a null value, which is special. Null should be replaced someday with a special Trigger type, to make sure that it does not conflict with a potential valid null param (which I see potential uses, like setting a reference as a param). So, the way you implemented gd-YAFSM, yes it's the case. But semantically and logically, they are two different beasts.
I agree with the first challenge. I disagree with the second. I think that the motto With great power comes great responsibility applies here. We let the user to setup their own conditions in a script language, so in my book, they have to make sure that their use of the params is not prone to bugs. Ironically, you forgot a potential solution in your list. One simple way to make sure the right type of default value is... to reimplement ConditionGroups. Let me explain: condition groups remove 95% of the need for expression conditions. You want either triggers to work? Simple, just create 2 condition groups. Want Sure, ExpressionCondition could stay, but as an advanced feature. A seldom used advanced feature. The reasoning behind not using Condition Groups in the project was the fact that it was easy to use We cannot have the cake and eat it too. I know you want to make gd-YAFSM dead simple to use, but expressions are an advanced feature. Either we reorganise the way conditions work to reduce the need to use the advanced feature, or we embrace the fact that expressions are an advanced feature. |
Internally, yes, they works differently, but I really don't see the point of presenting it as anything else, as from user's perspective, a trigger is much like a boolean that stays for 1 frame. However, I do agree that triggers should be stored in its own dictionary separating from parameters, which should be easy enough that it wouldn't even cause any breaking changes.
But currently, there's no way to declare default values at all, the only workaround would be setting parameters in I disagree taking Expression class as a fully working scripting language like gdscript, the purpose of the API being exposed is to act as a tool to interpret math expression like what the inspector do. Otherwise, this feature would be called ScriptCondition that makes use of Script.
Well, this is how I see those solutions:
The thing with those advance condition(ConditionGroup or ExpressionCondition) is that, they are not necessary. Even for now, we can already make complex condition the only drawback is that writing more code, for example, That's why I would rather spend more time to figure out a more flexible solution like ExpressionCondition. Btw, I think we should keep the discussion related to how we gonna make ExpressionCondition works. |
This PR adds a new condition based on the Godot class Expression for making complex conditions.
The user can enter an expression using params as variables. The condition will pass if the expression returns true, or will fail if there is an error or if the expression returns false.
For triggers, it's a little more complicated. As triggers are null params values, and Godot expects named input variables, it's not possible to directly use triggers in the condition. The same could be said standard params, but usually, params are continually there, but updated. Triggers are currently deleted from params after use.
So, to be able to test true or false on a trigger, "trigger" in the expression can accept parameters and will return true or false if they exist. So, expressions like this are possible:
trigger["board"] and height > 50.0
This intends to fix in part #21
Here's some screenshots of my PR: