I'm not sure there is a good way to dynamically make it where what values are exported varies based on the node itself. You could maybe get something working with _get_property_list
, though then you'd need to implement the setter and getter functions using _set
and _get
, which would have a decent amount of boiler plate code.
What I might suggest doing is implementing a base class that contains everything both nodes will need, and then extend the class for each node and export the variables there. Something like this, for example:
# base class
# ============
class_name base_class
extends Node
var animal_sound = "bark"
var animal_name = "dog"
func make_animal_noise():
print (animated_name + " makes sound: " + animal_sound)
# ============
# first class
# ============
extends base_class
export (String) var new_animal_sound = "moo"
func _ready():
animal_sound = new_animal_sound
make_animal_noise()
# ============
# second class
# ============
extends base_class
export (String) var new_animal_name = "duck"
func _ready():
animal_name = new_animal_name
make_animal_noise()
# ============
Then you can share the majority of the functionality by implementing it in the base class and only overriding/setting the values you need by extending and exporting variables. That is what I would recommend doing if you need to have exported variables that differ but share the same base functionality between multiple scripts/nodes.