Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Titox |
I have a node structure as
-Control
Buttons (A Control node)
Sprite
In the root node, I have a script which is meant to add 50
buttons to the 2nd Control node.Well its not working at all ie it does not display any button at all but when I outputprint(get_node("buttons.get_children()))
it gives me this:
[[Button:1142]]
[[Button:1142], [Button:1147]]
[[Button:1142], [Button:1147], [Button:1152]]
[[Button:1142], [Button:1147], [Button:1152], [Button:1157]]
[[Button:1142], [Button:1147], [Button:1152], [Button:1157], [Button:1162]]
[[Button:1142], [Button:1147], [Button:1152], [Button:1157], [Button:1162], [Button:1167]]
[[Button:1142], [Button:1147], [Button:1152], [Button:1157], [Button:1162], [Button:1167], [Button:1172]]
[[Button:1142], [Button:1147], [Button:1152], [Button:1157], [Button:1162], [Button:1167], [Button:1172], [Button:1177]]
[[Button:1142], [Button:1147], [Button:1152], [Button:1157], [Button:1162], [Button:1167], [Button:1172], [Button:1177], [Button:1182]]
[[Button:1142], [Button:1147], [Button:1152], [Button:1157], [Button:1162], [Button:1167], [Button:1172], [Button:1177], [Button:1182], [Button:1187]]
[[Button:1142], [Button:1147], [Button:1152], [Button:1157], [Button:1162], [Button:1167], [Button:1172], [Button:1177], [Button:1182], [Button:1187], [Button:1192]]
[[Button:1142], [Button:1147], [Button:1152], [Button:1157], [Button:1162], [Button:1167], [Button:1172], [Button:1177], [Button:1182], [Button:1187],
Etc
Yet it shows no button on the screen.I am sure that globals.CURRENT_LEVEL
is et to 50
Here is my code:
extends Control
var CURRENT_HIGHEST_LEVEL = globals.CURRENT_LEVEL
#onready var level_buttons = buttons.get_children()
var button_init_pos = Vector2(100,100)
# Called when the node enters the scene tree for the first time.
onready var buttons = get_node("Buttons")
func _ready():
print(buttons)
print(CURRENT_HIGHEST_LEVEL)
var i =1
for i in range(CURRENT_HIGHEST_LEVEL+1):
if i >0:
var button = Button.new()
var button_sprite = Sprite.new()
button_sprite.texture = load("res://assets/button ("+str(i)+").png")
button.add_child(button_sprite)
buttons.add_child(button)
print(buttons.get_children())
if i == 1:
button.set_position(button_init_pos)
else:
var prev_button = buttons.get_child(i -1)
button.set_position(Vector2(prev_button.get_position().x + 100, button_init_pos.y))
# print("The level chooser button at : "+str(i)+" has position :"+str(buttons.get_child(i).get_position()))