Skip to content
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

Add documentation on how to export variable at runtime with set() and get() #4320

Open
Shadowblitz16 opened this issue Oct 28, 2020 · 2 comments
Labels
area:manual Issues and PRs related to the Manual/Tutorials section of the documentation enhancement

Comments

@Shadowblitz16
Copy link

Shadowblitz16 commented Oct 28, 2020

Your Godot version:
3.2.3

Issue description:
I am trying to make a JSON resource importer but I'm not sure how to export dynamically created variables
Please add documentation on how to export variable at runtime with set() and get()

URL to the documentation page (if already existing):
https://docs.godotengine.org/en/stable/tutorials/plugins/editor/import_plugins.html

@Calinou
Copy link
Member

Calinou commented Oct 28, 2020

What do you mean by "exporting a variable at runtime"? Can you describe some possible use cases for this?

@Shadowblitz16
Copy link
Author

Shadowblitz16 commented Oct 28, 2020

like so..

func import(source_file, save_path, options, r_platform_variants, r_gen_files):
	var file = File.new()
	var err = file.open(source_file, File.READ)
	if err != OK:
		return err
	
	var dict = json2dict(file.get_as_text())
	
	file.close()
	var resource = parse_dict(Resource.new(), dict)
	resource.property_list_changed_notify()
	return ResourceSaver.save("%s.%s" % [save_path, get_save_extension()], resource)

func parse_dict(resource:Resource, dict:Dictionary)->Resource:
	var properties = resource.get_property_list()
	
	for i in range(properties.size()):
		var k = properties[i].name
		var v = properties[i].value
		if  v is Resource: resource.set(k, parse_dict(resource, v))
		else:              resource.set(k, v)
                # export(resource.get(k))
	return resource

@skyace65 skyace65 added the area:manual Issues and PRs related to the Manual/Tutorials section of the documentation label Dec 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:manual Issues and PRs related to the Manual/Tutorials section of the documentation enhancement
Projects
None yet
Development

No branches or pull requests

3 participants