Open gregcsokas opened 10 months ago
The issue with the proposed syntax is that it could conflict with member variables (or methods) called min
, max
and step
. Also, it could be misleading as people may think these are member variables when they're not. This should probably be a built-in keyword or global scope method instead.
built-in keyword or global scope method
That sounds good to me
It's already possible to min or max variables but it requires setter and getters functions.
@export var min_value: int = 1:
set(value):
min_value = clamp(value, -20, INF)
get:
return min_value
func _ready():
min_value = -500
print(min_value) # -20
Also, this won't show as a slider in the editor 🙃
1. You can use constant expressions as annotation arguments:
const VALUE_MIN = 0.0
const VALUE_MAX = 100.0
const VALUE_STEP = 0.1
@export_range(VALUE_MIN, VALUE_MAX, VALUE_STEP) var value: float = 0.0
2. You can get property information via get_property_list()
.
Describe the project you are working on
A 3D space game
Describe the problem or limitation you are having in your project
I'm working on a resource-based system for my game, and this resource has a bunch of
@export
values. In the resources, I don't have too many options to check if a value is higher than the range 'limits'. Basically, I need to control a timer with these values.I wrote a Component to handle these resources. The Component has a timer and every time the timer timeouts. I'm increment or decrement the value of the resource.
But currently the
value
can be higher than 100.0 so I need to check if it is higher or not.This is the component's code
Describe the feature / enhancement and how it helps to overcome the problem or limitation
With this proposal, I can get additional properties from the export. And in this specific case, I can control the value changes in my code.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
I don't know currently how this thing will work with the other
@export
variables! But for the enums, this is my best idea currently.If this enhancement will not be used often, can it be worked around with a few lines of script?
Yeah, but it's kinda a pain in the ass, I can use only the _init() function for this. and I need to get the hint_text from the get_property_list() convert it to the proper type, and save it into a variable.
Is there a reason why this should be core and not an add-on in the asset library?
It's related to the
@export
variables, and I don't think writing a plugin for it is possible.