Changing variables of an instance?

Freeman_ReignsFreeman_Reigns Posts: 27Member
edited July 28 in Programming

I'm trying to change the variable of an instance after creating it through code but just get the error message 'invalid set index 'number' (on base: 'KinematicBody2D') with value of type 'int'.

var instance = preload("res://Scenes/Units/Test/Unit1.tscn").instance()
instance.position = Vector2(1100, 600) = "Bob"
citizen_number += 1
instance.number = citizen_number

Maybe I'm misunderstanding how instances work, but aren't they essentially like copies of a node (including the script) that can be modified separately? I'd appreciate any help :)


  • AzedaxenAzedaxen Posts: 41Member

    Could you show the script on your Unit1 scene? I don't see anything in here that could cause that error. Your understanding of instances is correct, if you were to modify a value on the instance, it would be modifying a copy of that script. Generally that error shows up when you try to assign to a variable that doesn't exist on the class being referenced.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file