I have tried numerous times to make a dialog system. I have tried using Escoria, but I didn't like the bloat that came with it. I tried looking into json, but could not figure out how to get it to work. I have use arrays in Gdscript with some success, but I'm stuck at the moment. It brings up multiple options, but it doesn't load the text after or before.
Current gdscripts
My control.gd
extends Control
var dialogpath = "intro"
onready var container = get_node("scroll/choicecontainer")
var continued #A continued part of the dialog tree
var charname
var page = 0
onready var richtextbox = get_node("RichTextLabel")
func say(confab):
continued = confab#Stores the data path for later use
var dialog = load(confab).new()
charname = name
var charconfab = dialog.confab[dialogpath]
if page < charconfab.size():
richtextbox.set_bbcode(charconfab[page])
page+=1
print(page)
elif page >= charconfab.size():
page=0
richtextbox.set_bbcode(charname+": "+charconfab[page])
page+=1
func choice(dialogoption):
if dialogoption == null:#WIP
print("Error dialog returned null")
return
var newoption = load(dialogoption).new()
var option = newoption.dialogchoices
var i = 0
while i < option.size():
#Get a duplicate of the nodes
var dupchoice = get_node("dupchoice").duplicate()
var dupbutton = dupchoice.get_node("button")
var duplabel = dupbutton.get_node("label")
#Set Properties of the nodes
duplabel.set_text(option[i])
dupbutton.connect("pressed",self,"_on_pressed", [i])
var size = dupchoice.get_custom_minimum_size()
size.y = size.y + 15
dupchoice.set_custom_minimum_size(size)
dupchoice.set_hidden(false)#No longer hidden
#Adds the Choice duplicates to the Choice container
container.add_child(dupchoice)
i+=1
func _on_pressed(integer):
#Get the Integer for the option of the dialog tree.
dialogpath = "option"+str(integer)
print(dialogpath)
#Remove all the dialog options in the container.
var dupchoices = container.get_children()
for delchoices in dupchoices:
delchoices.queue_free()
#Continue the dialog
say(continued, charname)
In dialog.gd, this is reference by a character, by a export(String, FILE)var. If you use Escoria you should know what I mean.
var dialogchoices = ["Oh Yes Option 1 Is good","Option 2 might be better","Over here pick me!"]
var dialoger = {
intro = ["Hello can you pick an option?","You choose option one?"],
option0 = ["You choose option 0","NOT 1, Haha."],
option1 = ["You have option 2/1"],
option2 = ["YOU PICKED ME!","YAYAYAYAYYAYAYAYYAYAYAYYAYAYAYAYAYYAYAYAYAYAY!"]
}