Message Board


Message Board > Fenix / Bennu / Gemix / DIV > saving a struct to a file

March 20, 2007, 14:13
raverdave
Don't Give A F*CK
155 posts

Hi...I am wanting to save a struct like this:
STRUCT mymap[40]
xcoord;
ycoord;
END

to a file called levelx.lev ..... where x is the level number currently in use...

THEN!
read the file back into the structure...
____________
Gimme my toetag already...
#
March 20, 2007, 14:18
Moogle
Enterprise Edition
239 posts

save("levelx.lev",mymap);

And

load("levelx.lev",mymap);

!
____________
I am Moogle and I approve this message.

Quoting (. )( .) in the Bugs topic:
Everytime I login the threads with new posts are by Dennis.
#
March 20, 2007, 14:31
Eckolin
Quite Whiskered
388 posts

Code:
save("level"+itoa(levelnumber)+".lev",mymap);

load("level"+itoa(levelnumber)+".lev",mymap);


Or

Code:
if ((handle=fopen("level"+itoa(levelnumber),O_WRITE))>0);
fwrite(handle,mymap);
fclose(handle);
end

if ((handle=fopen("level"+itoa(levelnumber),O_READ))>0);
fread(handle,mymap);
fclose(handle);
end


[Edited on March 20, 2007 by Eckolin]
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
March 20, 2007, 14:53
raverdave
Don't Give A F*CK
155 posts

the first one worked great thanks eckolin,seems alot easier than i remembered vaguely div doing it,which i presume is the 2nd bit of code?? :D



Now another problem,using fpgedit,i cannot get the control point of a graph from the centre as it is by default!any ideas any1??

EDIT*** better spell right or some dumb ass american will jump on me..

[Edited on March 20, 2007 by raverdave]
____________
Gimme my toetag already...
#
March 20, 2007, 15:30
Eckolin
Quite Whiskered
388 posts

[Cryptic]

Edit
Control Points
Set center
To the right
Set new values
To the left

[/Cryptic]
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
March 20, 2007, 15:31
Sandman
F3n!x0r
1194 posts

Just add controlpoint 0, that's the center.
[EDIT]
Eckolin is too fast for me.

[Edited on March 20, 2007 by Sandman]
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
March 20, 2007, 15:34
raverdave
Don't Give A F*CK
155 posts

sorry,dont get ya..can you be abit clearer?


I imagined it to be like this:
http://raverdave.serveftp.com/files/snap.bmp

i select the top left dot like shown and press put centre...yeh i am wrong of course,but reference the snapshot to tell me why!

[Edited on March 20, 2007 by raverdave]
____________
Gimme my toetag already...
#
March 20, 2007, 15:45
g105b
None
86 posts
I have a level editor for my game, but the levels are much larger than yours. The struct is:

struct tile[19999];//200x100
    g;        //Graphic of the tile
    pass;    //If it is passable
    depth;    //Tile's Z, 0 is behind guy -1 is infront
end

Using save() and load() produced massive file sizes for each level, also writing the files using o_read() and o_write() caused the same imense file size...

When I had about 10 levels for the game, there was over 20 Mb in level data! That's when I experimented with z_read() and z_write(), the commands work almost identically to the normal read/write commands, but compress the data right down so I could have 50+ levels inside 1 Mb.

I doubt you will have large filesize problems with your smaller structs, but it could still be usefull for you :)

Oh and by the way, if you are compressing a struct into a file, don't just add the whole large struct into the file in one go or Fenix will crash. I add each value seperately inside a for loop.
____________
.g105b''
#
March 20, 2007, 16:10
raverdave
Don't Give A F*CK
155 posts

christ..I need medical help if anything,i had forgotten to set the screen mode,so it was in lowres,ALSO my struc should of indeed been bigger... [400] to be exact..god damnit...I can handle it from here! it as you can see http://raverdave.serveftp.com/files/mofo.PNG

[Edited on March 20, 2007 by raverdave]
____________
Gimme my toetag already...
#
March 20, 2007, 16:58
Eckolin
Quite Whiskered
388 posts

That .bmp took several minutes to load. For the version I use (0.40), the steps would be:

Put center.
Right arrow.
Set the values you want. (often 0,0)
Left arrow.
Accept.
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
March 20, 2007, 17:15
Eckolin
Quite Whiskered
388 posts

Glowing Ninja defines it's maps like this:

type _Tile;
soort; // Type of tile. Grass, cliff, etc.
ninja;
end

_Tile terrain[WORLD_WIDTH-1][WORLD_HEIGHT-1];

by the way. Using constants sometimes has advantages.

I'm considering changing terrain to a _Tile pointer for variable level sizes though.
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
March 20, 2007, 18:30
raverdave
Don't Give A F*CK
155 posts

lalala, yeh ...the bmp is on my server,and err..i am dloading torrents,which rape the bandwidth...
____________
Gimme my toetag already...
#

Message Board > Fenix / Bennu / Gemix / DIV > saving a struct to a file

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!