Hello,
Hopefully someone is willing to help. I have been trying to teach myself Godot 4 from the documentation, but have now hit a problem. Below is my code. I am trying to roll many dice and want them to display a random number. They are an instance from a different scene. I can set the “random” position with .position, but I would like to change the frame. The sprite2d has a spritesheet with the different numbers. I get this error:
invalid set index ‘frame’ (on base: ‘CharacterBody2D’) with value type of int
Thoughts?

var dice_scene = preload("res://dice.tscn")
func diceroll():
die = randi() % 6
var die_1 = dice_scene.instantiate()
die_1.position = Vector2(randf_range(200,400),randf_range(200,400))
die_1.frame = die
add_child(die_1)

invalid set index ‘frame’ (on base: ‘CharacterBody2D’) with value type of int

  • Toxe replied to this.

    Toxe Ahh, thank you, maybe.... My CharacterBody2D has a child node of a Sprite2D. Is it possible to access that?

    • Toxe replied to this.

      Use $name_of_sprite.frame

      jon_beeker2000 Yes, you can get the node like this:

      var sprite = die_1.get_node("Sprite2D") as Sprite2D  # adjust the node name as needed