Add a keyword to constant string type sharing it's name as string value. (as Syntax Sugar) #5151
JoanPotatoes2021
started this conversation in
Scripting
Replies: 2 comments 4 replies
-
I don't have further input about this but for the time being you can automate this the following way: # can't be `const` but let's pretend and use CONSTANT_CASE.
var WEAPON_DATA: String
var WEAPON_FIRE_SOUND: String
var WEAPON_RELOAD_SOUND: String
var WEAPON_MESH_PATH: String
var WEAPON_RELOAD_SPEED: String
func _init() -> void:
for p in get_property_list():
if p.name.begins_with("WEAPON_"): # or any other pattern
assert(p.type == TYPE_STRING)
set(p.name, p.name) For reference see also the GDScript style guide on how to name constants. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Hmm... I suppose that if this was valid syntax for creating a Dictionary, you'd no longer have this problem, either? # Notice the lack of assignment
const WEAPON = {
"DATA",
"FIRE_SOUND",
"RELOAD_SOUND",
"MESH_PATH",
"RELOAD_SPEED",
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone, here's an idea, syntax sugar for gdscript, 🍺 📑
Currently I am coding a lot of pointers to an library of constants to create a point in the code where all depedencies are stablished once, later I use those constants to load information from json files, so it works like:
Then later whenever I need to retrieve from a data bank the weapon fire sound, in code:
What if we could write like this on the autoload
Gamedata.gd
:I know we can do
var weapon_data := "weapon_data"
as well, I just like to use the var type definition explicity,The idea is
const_str weapon_fire_sound
=const weapon_fire_sound:String = "weapon_fire_sound"
Can this be done currently through other means? Or is my use-case too much specific and gross 💩 to implement in core?
This seems trivial, but it really bugs me having to type the same thing twice everytime.
For ref, using currently >>
v4.0.alpha14.official [106b68050]
Relevant Github links:
godotengine/godot#20988
godotengine/godot#31896
Beta Was this translation helpful? Give feedback.
All reactions