#Help with JSON arrays (Godot 4.2)

1 messages · Page 1 of 1 (latest)

knotty musk
#

I'm making a game that needs to handle very large arrays (16607 entires) and i have 3 JSON lists:

  • round 1 responses
  • round 1 names
  • round 1 placements (solely numbers)
    the names and placements work completely fine without issue, but responses leads to an error "Invalid Call: Nonexistant function 'size' in base 'Nil'" and freezes the whole Godot Editor for a long time. I've uploaded the files for debugging. In Notepad++, I got rid of all bright yellow text as far as I'm aware, but the responses still break Godot Editor.

Here is the code:

extends Label

var rng = RandomNumberGenerator.new()
var number = 0
var round1_responses = []

var json_text = ""

# Called when the node enters the scene tree for the first time.
func _ready():
    read_json_file("res://round1responses.json")
    round1_responses = parse_json(json_text)

func parse_json(text):
    var json = JSON.new()
    var result = json.parse(text)
    if result == OK:
        return JSON.parse_string(text)
    else:
        print("uh oh")
        return null

func read_json_file(file_path):
    var file = FileAccess.open(file_path, FileAccess.READ)
    var content_as_text = file.get_as_text()
    json_text = content_as_text

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
    if Input.is_action_just_pressed("space"):
        rng.randomize()
        number = (rng.randi_range(1,round1_responses.size()))-1
        text = str(round1_responses[number])+"
Written by: one of 16607 ewowers"
knotty musk
#

Update: I've fixed it, I just had to get rid of all backwards slashes \ in the responses