How to fix error code: "Invalid get index 'end_idx' (on base: 'Dictionary')."

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Katso

Im using The Dialogic Add-on in Godot and when i try to end the dialog timeline i get the error code: Invalid get index ‘end_idx’ (on base: ‘Dictionary’).

This error code is in the script

This is a section of the function that holds the error:

func _load_event():
	# Updates whether the event is the last text box
	if dialog_index + 1 >= dialog_script['events'].size():
		is_last_text = true
		# Get next event
		var next_event = dialog_script['events'][dialog_index + 1]
		# If next event is Text Event, is_last_text is false
		if next_event['event_id'] == "dialogic_001":
			is_last_text = false
		# Else, if next event is End Branch, set is_last_text to whether the next after exceeds the size of events.
		elif 'end_branch_of' in next_event:
			is_last_text = dialog_index + 2 >= dialog_script['events'].size()
		# Else, if next event is Choice (and current event is not a Question)
		elif 'choice' in next_event and not 'options' in dialog_script['events'][dialog_index]:
			# Get Question
			var index_in_questions = next_event['question_idx']
			var question = questions[index_in_questions]
			var index_in_events = dialog_script['events'].rfind(question, dialog_index)
			var end_index = question["end_idx"] #this is the code that is broken
			is_last_text = end_index + 1 >= dialog_script['events'].size()
	if dialog_script.has('events'):
		if not _is_dialog_finished():
			var func_state = event_handler(dialog_script['events'][dialog_index])
			#if (func_state is GDScriptFunctionState):
			#	print(func_state)
			#	yield(func_state, "completed")
		elif not Engine.is_editor_hint():
			# If setting 'Don't Close After Last Event' is not checked, free it.
			if not current_theme.get_value('settings', 'dont_close_after_last_event', false):

im using version v3.5.2.stable.official [170ba337a]

Edited to fix forum code formatting…

jgodfrey | 2023-06-01 19:06

:bust_in_silhouette: Reply From: jgodfrey

It’s not clear what "end_idx" is supposed to be. As written, it’s a simple string, meaning that your Dictionary needs to contain an item with the string key end_idx. The error indicates that your dictionary has no such key. On the other hand, if your dictionary uses integer values as keys and end_idx is a variable that contains one of those integer values, then reference should not be wrapped in quote marks (so, question[end_idx]).