Choosing random button position through script

Godot Version

4.1.2 stable

Question

I have two buttons in (64, 128) and (128, 128). Through randomize i choose one of them and give position of (350, 560). Im afraid, I not only dont understand how to set position for button but also how to get/pick node from randomizer.

func _ready() -> void:
	randomize()
	var Choose_to_Reposition = [$Button1, $Button2] # these are the names of the nodes in the scene
	print(Choose_to_Reposition.pick_random())
	
	var Result_of_Randomizer = Choose_to_Reposition.pick_random()
	var Reposition = Vector2(350, 560)
func _ready() -> void:
	randomize()
	var buttons = [$Button1, $Button2]	
	buttons.pick_random().global_position = Vector2(350, 560)

Note that moving the buttons will fail, if they are children of a container node.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.