Yeah, that was a tpyo… I wasn’t using my code, I was just explaining what the JSON file looked like…
This is my JSON file:
{
"Anon22310001": {
"EnemyCountry": "United States",
"EnemyIP": "192.168.132.140",
"EnemyMoney": 495,
"EnemyLevel": 1,
"EnemyXP": 0,
"EnemyNexp": 100,
"EnemyCloudSpace": 200,
"EnemyAttack": 9,
"EnemyPenetration": 4,
"EnemyDefense": 9,
"EnemySurvellience": 1,
"EnemyHealth": 225,
"EnemyDamage": 8
},
"Anon22002193": {
"EnemyCountry": "United Kingdom",
"EnemyIP": "192.168.220.342",
"EnemyMoney": 750,
"EnemyLevel": 2,
"EnemyXP": 0,
"EnemyNexp": 100,
"EnemyCloudSpace": 200,
"EnemyAttack": 11,
"EnemyPenetration": 5,
"EnemyDefense": 11,
"EnemySurvellience": 2,
"EnemyHealth": 270,
"EnemyDamage": 11
}
}
However I don’t think my error is with the JSON File.
The error is thrown in my NPCs.gd (load_enemy_data func):
func load_enemy_data(file_path: String) -> void:
var file = FileAccess.open(file_path, FileAccess.READ)
print("FILE OPENED...")
if file:
var json_data = JSON.parse_string(file.get_as_text())
print("WHETHER SUCCESSFUL OR NOT JSON PARSED...")
if json_data.error == OK:
print("IS JSON_DATA MORE THAN 0?")
if typeof(json_data.result) == TYPE_DICTIONARY:
enemy_data_dict = json_data.result
print("Loaded Enemy Data Successfully")
file.close()
else:
print("JSON Error: Parsed Data is not a Dictionary")
else:
print("Error parsing JSON: ", json_data.error_string)
file.close()
else:
print("Failed to open File: ", file_path)
All of my print("Wierd data within print) is just to debug so I know where the problem is…
I read the docs, and unless I understood it wrong, JSON.parse_string() doesn’t allow you to use (json_data.error)…
Specifically .error cannot be used in a parse_string() func…
I need to use JSON.parse() func in order to use .error == OK but I am still struggling to do that… Lol