I can see the response gets successfully in the desired variable:
my json file is generated from a node application ant its completely automatic. So there’s no error in json file. But it is 19000 lines . I though maybe it’s to much for gdevelop and tried the other examples in my local.
this is the example : GDevelop 5
A side not here the current desktop applications request action parameters different than this example’s a little bit (but thats not the case requests works fine )
this exactly same example doesn’t work on local either . I am comparing json structures they are just same . They both don’t use escape quotes , simple json.
Just tested and JSON parsing works fine. So it’s possible that or you have too many characters (JSON has some strict limits on max characters, as does Javascript. I think JSON is in the smaller of the two.), or you have a ton of special characters that would likely be invalid in a normal variable within the engine without being escaped.
I’d say try the other way around.
Make a test structure variable with a child that has a number, a child that has test, and a child that has a URL.
Use the ToJSON expression (global, scene, or object depending on which variable you made) from the expression builder, select the top structure variable, and store that in another string variable. See how it looks in the debugger, and also try exporting it to a text file and see how it looks there.
Hi , i didn’t understand the exporting to a text file , which action should i use for it , also i didn’t see any relation with the approach you suggest , in which part it should help me ?
i will upload my config.json file here too , maybe you want to try read it and parse it on your machine ?
There are actions to create a json or text file in the filesystem actions. You can send your variable to that action and it’ll create a file in your folder for you. You shouldn’t need to go that far, but it may help you do a one to one comparison.
If you do the rest of the recommendation, including creatiing the structure variable, converting it to json and storing that in a string variable, then looking at the string variable in the debugger you can get pretty close and see if you have any formatting errors.
I’m sorry, but I am not going to debug a 19000 line file, and since it seems like you have a requirements/format issue (either past maximum limits or invalid characters) and not an events one, the only way me getting the file would help would be if I went through it line by line.
Network actions are asynchronous, meaning it does little bits if work between each frame instead of blocking everything to do it at once, because network requests are slow and long. The results is therefore not put into the variable until a few frames later, use a separate event that checks if the variable was filled and only then parse it.
As you can see in the console log, the JSON text that was fed to the JSON parsing action is [Structure], which is what VariableString returns if you are getting a structure as a string. That is concerning because it is not the default type of a variable (number 0), so you must be using somewhere somehow fetchResponse as a structure, which converts it to a structure discarding the string value it could have had. Try to log ToJSON(fetchRepsonse) just before parsing it to try and identify what kind of data has been stored and what events could be responsible.
I have defined it as a structure type scene variable , i though having this ready would be good.
The asynchron behavior came to my mind too but i couldn’t be sure if request action waits to finish or not . I tried the check if fetchResponse equals to empty string , then tried to parse but didn’t fall on it too much. Will try again.
I am able to save fetchResponse as a structure now , and the problem was asynchronous behavior of web requests.
But i am parsing /logging/writing a file every frame now , otherwise it doesn’t work . Here screenshot which works (obviously this runs every frame not efficient for huge json)
I want to wait for fetch results like await keyword in js , and tried below approach but it didn’t worked , any suggestions ? i see console logs “triggered once” , but other logging/parsing didn’t work
Found the solution
It was right in front of my eyes the whole time . I just needed to check if VariableString(fetchResponse)!= “0” instead checking with “” . Cause gdevelop initialize empty strings to “0” not " " (i wonder why) . So approach for waiting web request was okay .
Because the default type of a variable is a number. The default value of a number is 0. If you get a number as a string, it will return a string representation of the number.
Therefore, unless you initialize a variable as an empty string, it will initialize itself to the number 0 when used the first time. Once used as a string, it will transform itself into the string “0”.
Well, guess what I have been working on for the last few months