0 votes

Hey,

I have been following the following tutorial:

[Tutorial I have been following ][1]

But i have ran into a problem as I am receiving an error or line 34 with the DialogManager.gd and this script was already created as it cam with the addon and I am also getting an error on line 34 with the script that is attached to the panel.

The DialogManager.gd script is

extends Node

export (String, FILE, "*.json") var dialog_file = null

var nodes = {}
var conversations = {}
var default_conversation = null
var current

signal new_speech(speech_codes)
signal new_choice(choices)
signal dialog_finished()

func _ready():
    parse_dialog_data()

func parse_dialog_data():
    if dialog_file:
        var file = File.new()
        file.open(dialog_file, File.READ)
        var data = parse_json(file.get_as_text())
        file.close()
        for graph_node in data["nodes"]:
            #var instance = load("res://addons/dialog_graph/" + data["nodes"][graph_node]["type"]).instance()
            match data["nodes"][graph_node]["type"]:
                "Conversation": create_conversation(data, graph_node)
                "Speech": create_speech(data, graph_node)
                "Choice": create_choice(data, graph_node)
                "Condition": create_condition(data, graph_node)
                "Mux": create_mux(data, graph_node)
                "Jump": create_jump(data, graph_node)

func start_dialog(conversation = default_conversation):
    current = conversations[conversation]
    process_conversation()

func continue_dialog():
    process()

func process():
    if current:
        match nodes[current]["type"]:
                "Conversation": process_conversation()
                "Speech": process_speech()
                "Choice": process_choice()
                "Condition": process_condition()
                "Mux": process_mux()
                "Jump": process_jump()
    else:
        emit_signal("dialog_finished")

func create_conversation(data, graph_node):
    var next = null
    if data["sc"].has(graph_node):
        next = data["sc"][graph_node]["0"]["to"]
    nodes[graph_node] = {"type": "Conversation", "next": next}
    conversations[data["nodes"][graph_node]["Line0"]] = graph_node
    if data["default_conversation"] == graph_node:
        default_conversation = data["nodes"][graph_node]["Line0"]

func process_conversation():
    current = nodes[current]["next"]
    process()

func create_speech(data, graph_node):
    var next = null
    var size = data["nodes"][graph_node]["Size"]
    if data["sc"].has(graph_node):
        next = data["sc"][graph_node]["0"]["to"]
    nodes[graph_node] = {"type": "Speech", "next": next, "size": size}
    var speech = []
    for i in range(size):
        #nodes[graph_node]["speech" + String(i)] = data["nodes"][graph_node]["Line" + String(i)]
        speech.append(data["nodes"][graph_node]["Line" + String(i)])
    nodes[graph_node]["speech"] = speech

func process_speech():
    emit_signal("new_speech", nodes[current]["speech"])
    current = nodes[current]["next"]

func create_choice(data, graph_node):
    var size = data["nodes"][graph_node]["Size"]
    nodes[graph_node] = {"type": "Choice", "size": size}
    if data["sc"].has(graph_node):
        var next = []
        for i in range(size):
            if data["sc"][graph_node].has(String(i)):
                next.append(data["sc"][graph_node][String(i)]["to"])
            else:
                next.append(null)
        nodes[graph_node]["next"] = next
    var choice = []
    for i in range(size):
        #nodes[graph_node]["choice" + String(i)] = data["nodes"][graph_node]["Line" + String(i)]
        choice.append(data["nodes"][graph_node]["Line" + String(i)])
    nodes[graph_node]["choice"] = choice

func process_choice():
    emit_signal("new_choice", nodes[current]["choice"])

func choice_picked(choice):
    current = nodes[current]["next"][choice]
    process()

func create_condition(data, graph_node):
    var next_true = null
    var next_false = null
    if data["sc"].has(graph_node):
        next_true = data["sc"][graph_node]["0"]["to"]
        next_false = data["sc"][graph_node]["1"]["to"]
    nodes[graph_node] = {"type": "Condition", "next_true": next_true, "next_false": next_false}
    var full_path = data["nodes"][graph_node]["Line0"]
    var split = full_path.find_last("/")
    var path = full_path.substr(0,split)
    var property = full_path.substr(split+1, full_path.length() - 1 - split)
    nodes[graph_node]["path"] = path
    nodes[graph_node]["property"] = property

func process_condition():
    var condition = get_parent().get_node(nodes[current]["path"]).get(nodes[current]["property"])
    if condition:
        current = nodes[current]["next_true"]
    else:
        current = nodes[current]["next_false"]
    process()

func create_mux(data, graph_node):
    var next = null
    if data["sc"].has(graph_node):
        next = data["sc"][graph_node]["0"]["to"]
    nodes[graph_node] = {"type": "Mux", "next": next}

func process_mux():
    current = nodes[current]["next"]
    process()

func create_jump(data, graph_node):
    var next = data["nodes"][graph_node]["Line0"]
    nodes[graph_node] = {"type": "Jump", "to": next}

func process_jump():
    current = conversations[nodes[current]["to"]]
    process_conversation()

And the panel script is:

extends Panel

onready var dialog_manager = $DialogManager
onready var dialog_text_box : Label = $Label

# Called when the node enters the scene tree for the first time.
func _ready():
    dialog_manager.start_dialog()

func _on_DialogManager_new_speech(speech_codes):
    dialog_text_box.text = speech_codes[0]
    pass

Here is a screenshot of the issue:

https://imgur.com/0CbHf9H

Any help appreciated and thank you in advance

in Engine by (32 points)

1 Answer

0 votes

The error is telling you exactly what is wrong. You are trying to access conversations[null]. The default value for the parameter conversation is null, so you must be calling start_dialog() without a value somewhere.

by (1,581 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories