I just don't get map-saving and loading working.. because I use arrays with different names in my editor, and I don't use the array-elements with index 0, the function looks a bit different, but I don't know, why it doesn't work...
I've written this functions:
1. Save
FUNCTION SAVE_LEVEL(name$)
`clean_boxes()
`clean_spawns()
`clean_wspawns()
rem Box
dim _b(ColBoxCount-1,3)
rem Player-Spawn
dim _s(SpawnCount-1,1)
rem Weapon-Spawn
dim _w(WSpawnCount-1,1)
rem Save boxes to array
boxes = ColBoxCount
For t = 1 to boxes
_b(t-1,0) = ColBox(t).x1
_b(t-1,1) = ColBox(t).y1
_b(t-1,2) = ColBox(t).x2
_b(t-1,3) = ColBox(t).y2
next t
rem Save playerspawns to array
spawns = SpawnCount
For t = 1 to spawns
_s(t-1,0) = spawn(t).x
_s(t-1,1) = spawn(t).y
next t
rem Save Weaponspawns to array
wspawns = WSpawnCount
For t = 1 to wspawns
_w(t-1,0) = wspawn(t).x
_w(t-1,1) = wspawn(t).y
next t
rem Create new directory for this level
make directory "Level"
make directory "Level"+name$
rem Write Array-Counts to info-file
if file exist("Level"+name$+"info")=1 then delete file "Level"+name$+"info"
open to write 1,"Level"+name$+"info"
write string 1,str$(ColBoxCount)
write string 1,str$(SpawnCount)
write string 1,str$(WSpawnCount)
close file 1
rem Save Boxes, Spawns and Weaponspawns
save array "Level"+name$+"boxen.info", _b(0)
save array "Level"+name$+"spawns.info", _s(0)
save array "Level"+name$+"wspawns.info", _w(0)
rem Delete temporary used arrays
undim _b(0)
undim _s(0)
undim _w(0)
ENDFUNCTION
2. Load
function OPEN_LEVEL(name$)
rem Exit if map does not exist
f$ = "Level"+name$+""
if path exist(f$) = 0 then exitfunction 0
rem Check if all files exist
i$ = f$ + "info"
b$ = f$ + "boxen.info"
s$ = f$ + "spawns.info"
w$ = f$ + "wspawns.info"
if file exist(i$)=0 then exitfunction -1
if file exist(b$)=0 then exitfunction -2
if file exist(s$)=0 then exitfunction -3
if file exist(w$)=0 then exitfunction -4
rem Files exist -> read information
open to read 1, i$
read string 1, c_b$
read string 1, c_s$
read string 1, c_w$
close file 1
rem Count-globals
ColBoxCount = val(c_b$)
SpawnCount = val(c_s$)
WSpawnCount = val(c_w$)
rem Used arrays
dim ColBox(ColBoxCount) as ColBoxType
dim Spawn (SpawnCount ) as SpawnType
dim WSpawn(WSpawnCount) as WSpawnType
rem temp arrays
dim _b(ColBoxCount-1,3) as integer : for x = 1 to ColBoxCount-1 : for d = 0 to 3 : _b(x,d)=rnd(1000)-500 : next d : next x
dim _s( SpawnCount-1,1) as integer
dim _w(WSpawnCount-1,1) as integer
rem Read arrays
load array b$, _b(0) `Boxes
load array s$, _s(0) `Spawns
load array w$, _w(0) `Weapons
Rem Copy arrays to real arrays
rem Boxes
for b = 1 to ColBoxCount
ColBox(b).X1 = _b(b-1,0) : print b : print _b(b-1,0)
ColBox(b).Y1 = _b(b-1,1) : print _b(b-1,1)
ColBox(b).X2 = _b(b-1,2) : print _b(b-1,2)
ColBox(b).Y2 = _b(b-1,3) : print _b(b-1,3) : print " - - - " : sync : wait 100 : if escapekey() then end
next b
undim _b(0)
rem Spawns
for s = 1 to SpawnCount
Spawn(s).X = _s(s-1,0)
Spawn(s).Y = _s(s-1,1)
next s
undim _s(0)
rem Weapon-Spawns
for w = 1 to WSpawnCount
WSpawn(w).X = _w(w-1,0)
WSpawn(w).Y = _w(w-1,1)
next w
undim _w(0)
endfunction 1
The open-function includes some debugging-commands... the "load array"-command doesn't seem to work. When I just create an array and load it then, all values are 0. If I give them random values, as done in this function, they stay random and aren't changed by "load array". That's strange... The array has the right size etc., right dimensions... right file-path... everything should be OK, but it doesn't work.
Has anybody an idea what could be wrong? Thanks...
Edit: Forgot to mention.. the maps created with my editor can't be opened with the original editor or with SS2 (game), and the SS2-Maps can't be opened with my editor...
Edit 2: OK, a friend helped me solving the problem.. there was just a problem with the array sizes, written in the info-file. So the main-features are included now, and I have to create a GUI and the next planned features...
By the way, new screenshot. Oo
Visit the DBPro - Speed up your game-Thread. http://forum.thegamecreators.com/?m=forum_view&t=88661&b=1