-
Notifications
You must be signed in to change notification settings - Fork 30
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
[RFC] Conditional Script Attributes #1196
Comments
How would you know when to evaluate the expression? |
All expressions for a script would be evaluated in order when any one of it's attributes is changed in the editor. So if a user toggles a check box, just naively iterated over all other attributes with conditions, and evaluate them with the current data |
I like it. But consider you want to safely run eval() already, could this be made more generic? Something like this.
|
The class is never actually initialized in the context of the editor. it would add a lot more complexity, and I'm not sure what the win would be |
other than "it would be amazing" I have nothing more specific at the moment :) |
I would definitely avoid using eval as much as possible. E.g.: post a link in forum/git, asking: "I have a bug, here is repro", users will follow it, and end up executing the XSS, as Editor is on The naming I would call "@visibleIf". it should be still an For the conditions, it is possible to do some simple parsing, with some defined syntax that devs should follow. E.g. tags search with multiple arrays is implemented for assets already, we can do for conditions a similar thing. Also, need to consider JSON type attribute, with a schema, and how it will work there - relative paths. |
Yep eval() is evil
Yep idiomatic JS scoped to the current script
Yes agreed /** @interface */
class Enemy {
hasWeapon = true
}
class Game extends Script {
/**
* @attribute
* @type [Enemy}
*/
enemy
/**
* @attribute
* @visibleIf {enemy.hasWeapon}
*/
displayWeapons
}
Looking up parent paths (ie an object attribute being conditional to a parent attribute) might be strange eg |
Would be amazing to have. Our physics script attributes are a huge wall of options that is cumbersome to use. |
It'd be great to have access to all members of the script, even if individual parts of it are broken into interface classes. I'd want to access another interface class attribute from a different interface class. Even better, maybe we could make all attributes of the entity available? A simple syntax to access local attributes: Access other script attribute: |
I would like to be able to show/hide attributes, based on the drop down menu selection. Similar to how default collision component behaves, when a collision type is selected. Might be similar or same to what @mvaligursky requested. |
+1 for conditional attributes. |
So I have an initial implementation of this. There are 2 attribute conditions Clipboard-20250130-154237-542.mp4Any feedback or thoughts appreciated. |
Can we use && and similar instead of "and"? |
Ha! Yes literally just discussed this. We'll stick to JS operators |
Does it support comparing with the current value of a drop down field? |
Not sure I 100% follow, but it would support attributes that depend on combobox attributes /** @enum {number} */
const LightsEnum = {
OFF: 0,
ON: 1,
UNKNOWN: 3
};
class DropDownDemo extends Script {
/**
* This is rendered as a dropdown
* @attribute
* @type {LightsEnum}
*/
lights = 0
/**
* This is only shown when lights dropdown is set to 'ON'
* @attribute
* @visibleWhen {lights === 1}
*/
number = 10
} |
Adds new conditional tags as per playcanvas/editor#1196 and playcanvas/attribute-parser#32
Adds new conditional tags as per playcanvas/editor#1196 and playcanvas/attribute-parser#32
Problem
It would be useful to have script attributes that only displayed under certain conditions. For example
Here we might only need to show the
bloomIntensity
slider to the user whenuseBloom
is enabled.There has been community demand for this:
#664
#278
https://forum.playcanvas.com/t/can-i-change-the-visibility-of-attributes-in-the-editor/36144/7
https://forum.playcanvas.com/t/can-we-change-the-script-attributes-by-the-type-of-an-enum/25865
Proposal
Implement a way to to declare dependencies between attributes
The
@attribtueWhen
(TBD) accepts a conditional expression that is evaluated to determine it's visibility eg:@attributeWhen {usePost && useBloom}
. The attribute control is enabled if the expression returns truthy.Alternative tag names
@attribute {expression}
@attributeWhen {expression}
Concerns
Any
{expression}
would need to be evaluated within the editor, and this is problematic if usingeval()
ornew Function
. eg@visbleWhen(while(true){})
. Instead the expression should be evaluated in some minimal sandboxed environmentThe text was updated successfully, but these errors were encountered: