Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | TickleTigger |
i’ve been trying to follow a tutorial for making a clicker game and my code looks identical to the one shown in the video, and im trying to store the count variable to a file. (The full script in the video can be seen at ~26 minutes in.)
When I try to run it it closes immediately and tells me “Invalid get index ‘count’ (on base Nil) ,” and it points out the following line specifically.
count = data.count
The following is the full script.
extends Node
var autoclicker = 0
export var count = 0
func _ready():
var file = File.new()
if file.file_exists("user://save.txt"):
file.open("user://save.txt", File.READ)
var data = parse_json(file.get_line())
count = data.count
func _on_Make_a_Thing_pressed():
count += 1
func _process(delta):
$Thngs.text = str(count)
func _on_SavingTimer_timeout():
var data = {
count = count
}
var file = File.new()
file.open("user://save.txt", File.WRITE)
file.store_line(to_json(data))
file.close()
Any help is much appreciated!