Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Anastasia |
Here’s the code im starting with
extends RichTextLabel
var dialog
var page
func _ready():
dialog = ["Hello player!", "How are you?" ]
page = 0
set_bbcode(dialog[page])
set_visible_characters(0)
set_process_input(true)
func _input(event):
if Input.is_action_pressed("ui_accept"):
if get_visible_characters() > get_total_character_count():
if page < dialog.size()-1:
page += 1
set_bbcode(dialog[page])
set_visible_characters(0)
func _on_Timer_timeout():
set_visible_characters(get_visible_characters()+1)
I have two buttons that ‘branch’ the dialogue: i call them A and B
Here’s my aproach:
extends RichTextLabel
var BRANCH_1 = false
var BRANCH_2 = false
var dialog
var page
var start = true
var A
var B
func _ready():
A = get_node("../1")
B = get_node("../2")
A.hide()
B.hide()
if start == true:
dialog = ["Hello player!", "How are you?" ]
page = 0
set_bbcode(dialog[page])
set_visible_characters(0)
set_process_input(true)
if start == false:
if BRANCH_1 == true:
page = 0
dialog = ["oh thats great!", "Awsome!"]
if BRANCH_2 == true:
page = 0
dialog = ["That's fine too!","hold on buddy"]
# warning-ignore:unused_argument
func _input(event):
if Input.is_action_pressed("ui_accept"):
if get_visible_characters() > get_total_character_count():
if page < dialog.size()-1:
page += 1
set_bbcode(dialog[page])
set_visible_characters(0)
if start == true:
if page == 1:
A.show()
B.show()
else:
A.hide()
B.hide()
func _on_Timer_timeout():
set_visible_characters(get_visible_characters()+1)
func _on_1_pressed():
#Great!
start = false
BRANCH_1 = true
func _on_2_pressed():
#Ok
start = false
BRANCH_2 = true
If you got any diferent solutions or an idea why this doesnt work, please!
Could you describe your problem? You say it doesn’t work, but not what happens.
Basic troubleshooting:
-
Are
_on_Timer_timeout
,_on_1_pressed
and_on_2_pressed
properly connected? -
You handle switching between branches in the
_ready
function, which only runs when the node first enters the tree. Either you forgot to move it into_process
, or you skipped the tutorials: Scripting (continued) — Godot Engine (3.2) documentation in English -
In the
_input
function, you only check ifui_accept
was pressed to switch pages. Looks like you could just press enter when the buttons show and completely skip the choice.
Bernard Cloutier | 2020-02-26 16:55