I've been tinkering a lot with my new game in the background, but I've come to a point where I need to ask something. I've tried "node.get_property_list()"..but that does not seem to give me the properties that I have defined in the script..either that, or I've over looked them..since it spits ALL the properties out. I could parse all that out, but I thought someone here might have an easy answer while I concentrate on other things....

what it boils down to..I need to get: property type, property name and value.

Have you defined setter and getter functions for them?

I understand all that :). I was just wondering if there was a simple way to output everything to a list like the get property list function?..That function itself feels a little misleading, looks more like a dict than a typical list. It's fine if the answer is "no". I can manually get all the variables I need...I just thought it would be faster to fill them into a list, read the type and act accordingly... I'm just doing some rudimentary testing for saving and loading...seeing if I can automate as much as possible.

I'VE WRITTEN A SAVE LOAD SYSTEM BEFORE(oops caps)...but not in godot...it's not a complicated thing. I actually have not touched any of it today..just busy with life stuff. I had seen that before. I just don't like to type a lot of variables over and over :). I really don't need to save every single variable anyway... I'll mark this up as "not natively supported in gdscript"...I may do some sorcery to get it working "my way"... Thanks anyway.

thanks, I'm fairly aware of these common methods. I'm not trying to come across as being rude...it's just not the path I was aiming for..BUT...I can make use of the string conversions...I used them in a few places when I was still developing "tiny RPG".

I feel like you'll have to define what it is you want to save/load at some point. Not sure there is a way to avoid it.

I found something that might help:

get_script().get_script_property_list()

That gives only the user defined variables.

You can use it like this:

var im_a_string : String = "something"
var im_an_int : int = 777

func _ready():
	get_script_test()
	
func get_script_test():
	var props = get_script().get_script_property_list()
	for prop in props:
		print("name: ", prop.name, ", value: ", get(prop.name), ", type: ", prop.type)

Note the type that is returned is an int into the enum Variant.Type, you can see what that translates to here. You'd just have to make a switch statement that compares the numbers, but you'll only need to write that once. https://docs.godotengine.org/en/3.2/classes/class_@globalscope.html#enum-globalscope-variant-type

! eureka ! That's it...get_script_propery_list()...that is all I needed, and I was only looking for the user defined variables... I can add prefixes to sort the "types" with some simple string manipulation. Thank you very much...I still have not gotten back to it, but I made a note in my docs. Thanks again.

hm...I just did a really quick test... (ignore the formatting, can't get the code formatting to work correctly, cut and paste does not seem to work :) )

var props = []

func _ready():
    props = get_tree().get_root().get_node("main/DirectionalLight").get_script().get_script_property_list()
    
    print(props)

and it's returning a value of 8192 for everything..according to the docs...

PROPERTY_USAGE_SCRIPT_VARIABLE = 8192 --- The property is a script variable which should be serialized and saved in the scene file.

I've also tried appending them individually into another list(of lists)..but it still returns 8192 as the value stored. I made this node specifically to test and gave it a few per-initialized varibles...but, not really certain how I get the value out of this?

It works if you do it like this:

onready var light_node = get_node("DirectionalLight")

func _ready():
	var props = light_node.get_script().get_script_property_list()
	print(props)
	for prop in props:
		print("name: ", prop.name, ", value: ", light_node.get(prop.name), ", type: ", prop.type)

ok, I will check. I made the assumption that getting the reference in ready is the equivalent..but I'm sure you're correct. I'll go check. so I can close this :)

ok, that does work. I'm just curious as to why..I see as I type this...need to reference the dict names..I never use dicts..and I'm not a very strong coder :)

That does answer my question and it works as I was planning on having it work. Thanks again.

2 years later