Invalid get index 'bought' (on base: 'Nil'). WHY?

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


i’m doing a flappy bird game with shop.
buy button should switch to selected when I buy something but that doesn’t work. everytime when i click on “buy” it crashes. code:

 extends Tabs

onready var price2 = str2var($RichTextLabel/Control/Panel2/Label.text)
onready var price3 = str2var($RichTextLabel/Control/Panel3/Label.text)
#onready var price4 = str2var($RichTextLabel/Control/Panel4/Label.text)
#onready var price5 = str2var($RichTextLabel/Control/Panel5/Label.text)
onready var panels = $RichTextLabel/Control

func _ready():
	pass # Replace with function body.

func _process(delta):
	$RichTextLabel/Control.position.y = -$VScrollBar.value
func _buy(price, item_no):
	if GameManager.points >= price:
		GameManager.points -= price[item_no] = true
		panels.get_node('Panel' + str(item_no)).get_node('Button').text = 'SELECT'
		var rem = price - GameManager.points
		$ColorRect/Label.text = 'You need '+str(rem)+'points \n to buy this'

func _on_Button_pressed():
	_buy(price2, 1)

func _on_Button2_pressed():
	_buy(price3, 2)

func _on_ok_pressed():
	$ColorRect.hide() code:

 extends Node

var points = 0
var shop = {
			'bought' : [true, false, false, false, false]
var save_shop_path = 'user://save'

func save_shop():
	var file =, file.WRITE_READ)
func load_shop():
	var file =
	if not file.file_exists(save_shop_path):
		return false, file.READ)
	shop = file.get_var()
	return true code:

extends Label

export(int) var price

func _ready():
	text = str(price)

its my first godot project and so far everything has gone well

pic of godot with buttons, label etc: Screenshot-2021-01-07-at-20-08-08 hosted at ImgBB — ImgBB

i hope u can help me…

Provided that your item_no reference is valid, either of these are correct ways to access your dictionary.[item_no] = true['bought'][item_no] = true

So, I don’t see a problem with that specific reference. Are you sure the error is in the code you posted?

jgodfrey | 2021-01-07 23:30

Yes, in:[item_no] = true

so in is the error but i don’t understand why :frowning:

felaix | 2021-01-08 10:41

:bust_in_silhouette: Reply From: Lopy

The error message tells you that is null. This likely comes from file.get_var() returning null, because it failed to find a var in the File, and indeed, you use file.shop_var(shop) instead of file.store_var(shop) when putting a value inside it.

i understand. thank you very much.

felaix | 2021-01-09 15:44

i renamed ALL in “store” now but i still get the same errors …

felaix | 2021-01-09 19:23

i copied all of code from the video and i get the errors:

E 0:00:01.585   decode_variant: Condition "len < 4" is true. Returned: ERR_INVALID_DATA
  <C++ Source>  core/io/marshalls.cpp:108 @ decode_variant()
  <Stack Trace> @ load_store()
       @ _ready()


E 0:00:01.585   get_var: Error when trying to encode Variant.
  <C++ Error>   Condition "err != OK" is true. Returned: Variant()
  <C++ Source>  core/bind/core_bind.cpp:2273 @ get_var()
  <Stack Trace> @ load_store()
       @ _ready()

i can’t understand this and i’m thinking about to end this project -.-

felaix | 2021-01-09 19:40