You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Turn-based RPG featuring hand-drawn 2D characters in a 3D space
Describe the problem or limitation you are having in your project
Overly verbose gdscript in value validation
Describe the feature / enhancement and how it helps to overcome the problem or limitation
# Current functionalityfuncdo_something(x, y=null):
# Default to `do_something(x, x)` if `y` is not providedy=yifyelsex# Use `x` and `y`# Desired functionalityfuncdo_something(x, y=null):
# Default to `do_something(x, x)` if `y` is not providedy=yorx# Use `x` and `y`
This can also be compounded for various levels of fallbacks:
varcached_values:= {}
# Assume load_value(key) will add the key-value-pair to the dictionary# and return the value or return null if the key is invalid# Current functionalityfuncget_value(key, default=null):
ifnotcached_values.has(key):
load_value(key)
returncached_values.get(key, default)
# Desired functionalityfuncget_value(key, default=null):
# Condensed a lot of logic into a single line with clear precedence of potential resultsreturncached_values.get(key) orload_value(key) ordefault
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
The "arbitrary" or operator will be a binary function taking two expressions, returning the first if it isn't null and the second otherwise. Similar to the boolean logical or/|| operators, the second expression will only be evaluated if the first is null. Effectively:
var x = (expression_a)
return x if x else (expression_b)
# Same functionality as
return (expression_a) or (expression_b)
If this enhancement will not be used often, can it be worked around with a few lines of script?
There's no clean way to lazy-evaluate expressions just within gdscript. It's possible with lambdas and bound callables, but significantly longer and arguably less readable:
Is there a reason why this should be core and not an add-on in the asset library?
Assuming it were a successful add-on, there would be a disruptive split in gdscript functionality with many users who take advantage of the asset potentially sharing code that confuses users who aren't aware of the add-on.
The text was updated successfully, but these errors were encountered:
Describe the project you are working on
Turn-based RPG featuring hand-drawn 2D characters in a 3D space
Describe the problem or limitation you are having in your project
Overly verbose gdscript in value validation
Describe the feature / enhancement and how it helps to overcome the problem or limitation
This can also be compounded for various levels of fallbacks:
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
The "arbitrary"
or
operator will be a binary function taking two expressions, returning the first if it isn'tnull
and the second otherwise. Similar to the boolean logicalor
/||
operators, the second expression will only be evaluated if the first isnull
. Effectively:If this enhancement will not be used often, can it be worked around with a few lines of script?
There's no clean way to lazy-evaluate expressions just within gdscript. It's possible with lambdas and bound callables, but significantly longer and arguably less readable:
Alternatively:
Is there a reason why this should be core and not an add-on in the asset library?
Assuming it were a successful add-on, there would be a disruptive split in gdscript functionality with many users who take advantage of the asset potentially sharing code that confuses users who aren't aware of the add-on.
The text was updated successfully, but these errors were encountered: