- Edited
Hi there people, i did try to randomly take 3 element(buttons) from an array and make them visible. and i did that, but there is a problem. When same element got selected randomly, one of them goes selected.visible = false
so what i need is, first: make that same button doesn't selected randomly same time or: its okay the return with the same button, but make it visible.
but, dont no how. i even supprise how did i write this down, i mean im pretty noob =) =) =)
soo, need help.
this is my code:
onready var ability1_a = get_node("ability1")
onready var ability2_a = get_node("ability2")
onready var ability3_a = get_node("ability3")
onready var ability4_a = get_node("ability4")
onready var ability5_a = get_node("ability5")
onready var ability6_a = get_node("ability6")
onready var ability7_a = get_node("ability7")
onready var ability8_a = get_node("ability8")
onready var ability9_a = get_node("ability9")
func _on_Button_pressed():
randomize()
var ability_select = [ability1_a,ability2_a,ability3_a,ability4_a,ability5_a,ability6_a,ability7_a,ability8_a,ability9_a]
var selected_1 = ability_select[randi() % ability_select.size()]
var selected_2 = ability_select[randi() % ability_select.size()]
var selected_3 = ability_select[randi() % ability_select.size()]
selected_1.visible = true
selected_2.visible = true
selected_3.visible = true
selected_1.set_position(Vector2(-10,0))
selected_2.set_position(Vector2(115,0))
selected_3.set_position(Vector2(240,0))
print ("first: "+selected_1.name," second: "+selected_2.name," third: "+selected_3.name)
also every TextureButton has this code on it:
func _on_ability8_pressed():
game_start_t.start(3)
$ability1.visible = false
$ability2.visible = false
$ability3.visible = false
$ability4.visible = false
$ability5.visible = false
$ability6.visible = false
$ability7.visible = false
$ability8.visible = false
$ability9.visible = false