Overkillz Posted September 28, 2017 Share Posted September 28, 2017 (edited) Hello dear guys, Im trying to use the following functions which are toJSON and fromJSON Well, I don't know when I use fromJSON I get some value changed. Why do I say this ? Well, in the table there are some booleans which will say if some objects will have "setElementCollisionsEnabled" or not. When I try to update the table from the file updated using fromJSON, collision is always false. That is an example. Sometimes the error is the position or something similar. I hope u can help me, thanks for reading. This error only happens when I use toJSON and fromJSON. (I bet that the error is on string.gsub) local tablaPrueba = { {"object","6959","3132.67969","-1632.39587","20.36549","0","90","0","0",true,"255","1"}, {"object","6959","3132.67969","-1632.39551","61.70512","0","90","0","0",true,"255","1"}, {"object","6959","3132.67969","-1592.40625","63.70512","0","90","0","0",true,"255","1"}, {"object","6959","3132.67969","-1592.40625","69.70512","0","90","0","0",true,"255","1"} } --CREATING THE FILE local fileHandle = fileCreate("tablaPrueba1.wha") if fileHandle then local json = toJSON ( tablaPrueba ) fileWrite(fileHandle,json) fileClose(fileHandle) end --LOADING THE FILE file = fileOpen("tablaPrueba1.wha") if file then local fileR = fileRead(file, fileGetSize(file)) fileR = string.gsub(fileR, "{", "[{") fileR = string.gsub(fileR, "}", "}]") fileR = fromJSON(fileR) tablaPrueba = fileR fileClose(file) end Edited September 28, 2017 by Overkillz Link to comment
Moderators IIYAMA Posted September 28, 2017 Moderators Share Posted September 28, 2017 You shouldn't be using string manipulate functions on JavaScript Object Notation, it might corrupt your file. Make sure you check your string after you generate it, afaik it should be converted correctly both ways. Debugging = understanding. iprint(tablaPrueba) local json = toJSON ( tablaPrueba ) iprint(json) iprint(fileR) fileR = fromJSON(fileR) iprint(fileR) 1 Link to comment
Overkillz Posted September 28, 2017 Author Share Posted September 28, 2017 Thanks for it, I have found the problem with ur help. When the objects were being added to the table, if they were false then they weren't added. 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now