Id consider using a combination of saving JSON files as well as using string tokens for setting up the raw data
You dont need to save in json format and can use your serialisation using WriteString,integer etc and just use string tokens to set up the data if you want to
// Project: DC
// Created: 2018-12-19
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "DC" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 0, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
global numberofobjects = 0
global temp = 0
type objects
name$
type$
sheetxpos
sheetypos
sizex
sizey
maxhealth
ability$
endtype
global object as objects[]
// CHeck if the file exists, if it doesnt then create it
if GetFileExists( "objects.dat" ) = 0
message("File "+chr(34)+"objects.dat"+chr(34)+" not found."+ Chr(10) +"I'll generate a new default objects.dat file")
// Create all the data from scratch and save it
CreateData()
SaveData()
endif
// load the data
LoadData()
do
print("Num Creatures: " + str(object.length))
for temp=0 to ((object.length)-1)
print(object[temp].name$+","+object[temp].type$)
print(str(object[temp].sheetxpos)+","+str(object[temp].sheetypos)+","+str(object[temp].sizex)+","+str(object[temp].sizey)+","+str(object[temp].maxhealth))
print(object[temp].ability$)
print("")
next temp
//print(f$)
// Print( ScreenFPS() )
Sync()
loop
function CreateData()
// insert all your raw data here line by line
dat$ = ""
dat$ = dat$ + "BlueSteelAU,Player,0,0,64,64,255,teleport,"
dat$ = dat$ + "Skeleton,Monster,65,0,64,64,255,none,"
dat$ = dat$ + "Ogre,Monster,68,0,64,64,150,Clubbing,"
dat$ = dat$ + "Wombat,Creature,32,0,64,64,200,none,"
dat$ = dat$ + "KillerBunny,Monster,158,0,64,64,5000,CarrotPunch,"
// you can add as much data as you like here ^^^
// Get the number of creatures
num = CountStringTokens(dat$,",")/8
// fill in an object and it
o as objects
for i=0 to num
o.name$ = GetStringToken(dat$,",",i*8 + 1)
o.type$ = GetStringToken(dat$,",",i*8 + 2)
o.sheetxpos = Val(GetStringToken(dat$,",",i*8 + 3))
o.sheetypos = Val(GetStringToken(dat$,",",i*8 + 4))
o.sizex = Val(GetStringToken(dat$,",",i*8 + 5))
o.sizey = Val(GetStringToken(dat$,",",i*8 + 6))
o.maxhealth = Val(GetStringToken(dat$,",",i*8 + 7))
o.ability$ = GetStringToken(dat$,",",i*8 + 8)
object.insert(o)
next i
endfunction
function SaveData()
// Save the data as serialised raw data
/*opentowrite (1,"objects.dat",0)
writeInteger(1,object.length)
for temp=0 to ((object.length)-1)
writeString(1,object[temp].name$)
writeString(1,object[temp].type$)
writeinteger(1,object[temp].sheetxpos)
writeinteger(1,object[temp].sheetypos)
writeinteger(1,object[temp].sizex)
writeinteger(1,object[temp].sizey)
writeinteger(1,object[temp].maxhealth)
writeString(1,object[temp].ability$)
next temp
closefile(1)*/
// Save the data as a JSON file but with extension ".dat"
object.save("Object.dat")
endfunction
function LoadData()
// read the data from the file
/*opentoread (1,"objects.dat")
numberofobjects = readinteger(1)
object.length=numberofobjects
for temp=0 to ((object.length)-1)
object[temp].name$=readString(1)
object[temp].type$=readString(1)
object[temp].sheetxpos=readinteger(1)
object[temp].sheetypos=readinteger(1)
object[temp].sizex=readinteger(1)
object[temp].sizey=readinteger(1)
object[temp].maxhealth=readinteger(1)
object[temp].ability$=readString(1)
next temp
closefile(1)*/
// Load the file data using JSON
object.load("Object.dat")
endfunction