// Project: loadingandsavingdata
// Created: 23-05-03
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "loadingandsavingdata" )
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( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
type weapons_type
weapontype as integer
dmg as integer
rps as integer
endtype
global weapons as weapons_type[]
global file$ as string
global SavedData as String []
global ThisFile as integer
global NumTokens as integer
global numguns as integer
global version as float
global versionnum as string
global levelnum as string
global finalversion as integer
global guntokens as String
global gunstats as string
global seperatedstrings as string[]
global loadedstring as string = "version:2.0|guns:0,42,12;1,23,2;2,14,3|powerups:0,23,3,5,powerups:1,34,67,0|levelnum:10|"
global done as integer = 0
global gunsfound as integer
global versionfound as integer
global levelfound as integer
global numstats as integer
do
local i as integer
local g as integer
loaddata()
if versionfound =1
print("version found")
endif
if levelfound = 1
print("level number found")
endif
if gunsfound = 1
print("guns found")
endif
for i = 0 to weapons.length
print("Gun:" + str(i)+ " type:" + str(weapons[i].weapontype))
print("Gun:" + str(i)+ " DMG:"+ str(weapons[i].dmg))
print("Gun:" + str(i)+ " RPS:"+ str(weapons[i].rps))
next i
Sync()
loop
function loaddata()
if done = 0
repeat
NumTokens = CountStringTokens( loadedstring, "|" )
For x = 1 to NumTokens
seperatedstrings.length = seperatedstrings.length + 1
seperatedstrings[seperatedstrings.length] = GetStringToken(loadedstring,"|",x)
Next x
for i =0 to seperatedstrings.length
if GetStringToken(seperatedstrings[i],":",1) = "version"
versionfound = 1
versionnum = GetStringToken(seperatedstrings[i],":",2)
elseif GetStringToken(seperatedstrings[i],":",1) = "levelnum"
levelfound = 1
levelnum = GetStringToken(seperatedstrings[i],":",2)
elseif GetStringToken(seperatedstrings[i],":",1) = "guns"
gunsfound = 1
guntokens = GetStringToken(seperatedstrings[i],":",2)
numguns = CountStringTokens(guntokens, ";" )
for g = 1 to numguns
gunstats = GetStringToken(guntokens,";",g)
numstats = CountStringTokens(gunstats, "," )
weapons.length = weapons.length + 1
weapons[weapons.length].weapontype = val(GetStringToken(gunstats,",",1))
weapons[weapons.length].dmg = val(GetStringToken(gunstats,",",2))
weapons[weapons.length].rps =val( GetStringToken(gunstats,",",3))
next g
endif
next i
done = 1
until done = 1
endif
endfunction
the code above i made to learn and practice with. my question is when using countstringtokens does it start at 0 or 1 because most of the " for i" loops i had to start at 1 to get the right data or it would just give me 0 for "0" except this line was the apposite "for i =0 to seperatedstrings.length"