Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | rudedudejk |
I am loading a JSON file, and instantiating scenes based on the JSON. I’m able to preload the scene, set it’s position dynamically from the values in the JSON, but I’m confused how I would set other arbitrary data onto a node’s script inside the new scene i created.
I have some code like this:
func _build_normal_star(star_data):
var star = preload("res://Scenes/Stars/Star.tscn").instance()
# this works fine
star.position.x = star_data["x"]
star.position.y = star_data["y"]
# The root node has a script with variables i'd like to set..
# This doesn't complain but not what i want.
# I've tried `get()` to access these attrs after i set them on the node, but that doesn't seem to work.
star.get_node(".").set("ships", star_data["ships"])
star.get_node(".").set("player_id", star_data["player"])
star.get_node(".").set("star_id", star_data["id"])
$Stars.add_child(star)
Is there a different way? star.get_node(“.”).get_script() is not the instantiated script to be able to set attributes. Looking for the correct pattern for loading data like this.
Thanks for any help, really enjoying learning Godot!