Aaron Craig
Member
I'm working on a card game and have created a json file to import all the card details. The problem is the parsed json changes the order it comes in, seemingly at random. It seems like if I add any extra code into my project, anywhere, it may change it. It only seems to alternate between two values, not totally change, but I can't understand why.
Here's the parsing code:
Then I take those values and save them:
I know I could build a sorting function for the returned values, but I thought this might be a language issue or bug. Has anyone else experienced this?
Here's the parsing code:
GML:
//Read in the cards from the file in the dataFiles folder of project
if (file_exists(working_directory + "creatures.json")) {
json = "";
//Open the file
file = file_text_open_read(working_directory + "creatures.json");
//Read the entire file as one string
while(file_text_eof(file) == false) {
json += file_text_readln(file);
}
file_text_close(file);
//Save the json in the global variable
global.MasterCardList = json_parse(json);
}
GML:
//Assign globals to the struct names
var array = variable_struct_get_names(global.MasterCardList[0]);
global.CardName = array[1]
global.CardType = array[4]
global.CardAttack = array[5]
global.CardDefense = array[6]
global.CardSpecies = array[7]
global.CardElement = array[8]
global.CardLevel = array[0]
global.CardAbilityText = array[2]
global.CardFlavorText = array[3]
Attachments
-
64.5 KB Views: 10
-
19.9 KB Views: 10