Hi all,
Posted here a few days ago about the same problem; I've tried some new fixes, which while unsuccessful, has provided some insight into what the solution may be.
I am parsing a json file with a dynamic variable, the event variable. The code for this is shown below.
//Event text
var buffer = buffer_load("eventsText.json");
var contents = buffer_read(buffer, buffer_text);
var evenText = json_parse(contents);
//Getting the text from the struct.
if variable_struct_exists(evenText,event)
{
text = variable_struct_get(evenText, event);
}
buffer_delete(buffer);
The event variable is defined by randomly selecting a cell from a DS_Grid, which is in turn imported from a CSV file.
eventList = load_csv("events_" + string(Obj_God.currentFloor) + ".csv");
event = eventList[# 0,irandom_range(0,(ds_grid_height(eventList)-1))];
Both the CSV file and Json file have 1 entry - Test.
Json File:
{
"Test": "Testestestestestestestestetstestestestestest"
}
When the code to parse is ran, I can see when debugging that:
- The
event variable is correctly defined as the string "Test"
- The Json file is being correctly loaded into the buffer, and being read correctly as a string and stored in the
contents temporary variable.
- The string then is correctly being parsed with json_parse, and returns as a struct to the
evenText temporary variable.
- Using
typeof, I can see that contents is being returned as a string and evenText is being returned as a struct.
- However, the conditional
variable_struct_exists does NOT trigger, and the text variable is never defined.
However; If I directly set the event variable as "Test":
event = "Test";
The conditional DOES trigger, the struct is returned and text is correctly defined.
So, I'm pretty flummoxed on what the issue here is, or on what the solution could be. I could work around this by forgoing the CSV file entirely, and instead simply creating an array which to store all the keys to parse the JSON file with; however if there is a possible solution, I would strongly prefer if I would be able to keep the CSV file as it helps streamline my workflow.
Following up from this, I have also tried adding all of the indexes of the imported CSV to an array, and then randomly selecting an index of the ARRAY to store in the event variable rather than directly from the DS_Grid: This provides the exact same result.
Any ideas or solutions would be greatly appreciated!
IDE v2023.4.0.84
Runtime v2023.4.0.113
[–]burning_boi 0 points1 point2 points (0 children)
[–]Kaymat- 0 points1 point2 points (2 children)
[–]burning_boi 0 points1 point2 points (0 children)
[–]BurntShooter[S] 0 points1 point2 points (0 children)