Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | X |
Hello! I’m testing a textbox system made for a old version of godot, it’s works fine, but the question/answer
feacture doesn’t. I found out that the problem it’s the fact that the index of the pressed button it’s alwais 0 for some reason.
func question(answer_array):
if show_debug_messages:
print("STARTED QUESTION FUNCTION")
btn_answers = VBoxContainer.new()
btn_answers.set_alignment(HALIGN_LEFT)
btn_answers.set_anchor(MARGIN_LEFT, ANCHOR_BEGIN)
btn_answers.set_anchor(MARGIN_TOP, ANCHOR_BEGIN)
btn_answers.set_anchor(MARGIN_RIGHT, ANCHOR_END)
btn_answers.set_anchor(MARGIN_BOTTOM, ANCHOR_END)
dialog_dup = duplicate()
dialog_dup.rect_size = btn_answers.rect_position
dialog_dup.visible = false
btn_answers.rect_position = (Vector2(0,0))
dialog_dup.set_script(null)
add_child(dialog_dup)
for child in dialog_dup.get_children():
child.queue_free()
#remove_child(btn_answers)
dialog_dup.add_child(btn_answers)
btn_answers.set_focus_mode(Control.FOCUS_CLICK)#grab_focus()
btn_answers.rect_size = (Vector2(0,0))
if position <= 1:
dialog_dup.rect_position = (Vector2(textObj.rect_position.x, get_viewport_rect().size.y/2))
else:
#question will appear on top of the dialog
dialog_dup.rect_position = (Vector2(textObj.rect_position.x, rect_size.y*-1))
var index = 0
for answer in answer_array:
var b = Button.new()
b.set_text(answer)
b.add_font_override("font", font)
b.set_flat(true)
b.add_stylebox_override("normal", StyleBox)
b.add_stylebox_override("selected", StyleBox)
b.add_stylebox_override("pressed", StyleBox)
b.add_stylebox_override("hover", StyleBox)
b.add_font_override("font_selected", font)
btn_answers.add_child(b)
b.connect("pressed",self,"selected_answer",[index])
if index > 0:
var last_child = btn_answers.get_child(index-1)
b.set_focus_neighbour(MARGIN_TOP,last_child.get_path())
btn_answers.rect_size.y += b.rect_size
index+=1
yield(get_tree(),"idle_frame")
btn_answers.get_children()[0].grab_focus()
yield(get_tree(), "idle_frame")
btn_answers.set_margin(MARGIN_RIGHT, 0)
dialog_dup.visible = true
dialog_dup.rect_size = btn_answers.rect_size
Can someone help me?
The problem it’s in this line:
b.connect("pressed",self,"selected_answer",[index])
I’m using this system: