invalid get index "Lu" (on base 'array')

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

I’ve been trying to get this A.P.I. up and running; but i got this error while debugging.

Invalid get index “Lu” (on base ‘array’)

here’s my code

    extends Control 

onready var bg_rect = get_node("Media_Sys/BG_Rect")
onready var char_sprite = get_node("Media_Sys/Sprite")
onready var text_box = get_node("Dialog_Sys/Dialog_Text")
onready var text_nam = get_node("Dialog_Sys/Label/Name")
onready var click = get_node("ClickManager")

var player = []

var lu = "Lu"
var ciel = "Ciel"

func _ready():

func write(char_name_str, text_str=null):
	if text_str == null:
		text_str = char_name_str
		char_name_str = ""
	player.push_front({"type": "dialogue","name": char_name_str, "text": text_str})
func write_component():
	text_nam.add_text(player[player[player.size() - 1]["name"]])
	text_box.add_text(player[player[player.size() - 1]["text"]])

func _input(event):

	if event is InputEventMouseButton:

extends Node

onready var g = get_parent()

var lu = "Lu"
var ciel = "Ciel"

func _ready():
	g.write("Lu", "hello")
:bust_in_silhouette: Reply From: leonidboykov


Check these lines

text_nam.add_text(player[player[player.size() - 1]["name"]])
text_box.add_text(player[player[player.size() - 1]["text"]])

you are using “Lu” and “hello” as indexes of player. Correct lines will be

text_nam.add_text(player[player.size() - 1]["name"])
text_box.add_text(player[player.size() - 1]["text"])

P.S. you can also use player.back() method to get last element of an array.

i got the same error this time it’s for “-1”, removing it give me the same error but with “1” this time

Lynn_Len | 2018-11-30 01:23

Are you sure if your array is not empty when you are accessing an item?

leonidboykov | 2018-11-30 05:00