![](sad.gif)
Map-Reading / Writing Algorithms
hi
i am writing a tile based RPG and now i am stopped on File Handling, i stopped because i have huge trubble to write or read a map.
can you give me some functions or code pieces of how do this thing. i am tried to manage this for to weeks´!!! when i tried to write for my self i recieved to much errors of thomething like acces violation or str != NULL ....
i realy need some help.
thx in Advance;
![](sad.gif)
.--=Nironics=--.
I really havent ever tried, to do this, because all of my games so far have not required my own file format, but Ive read a bit on file writing reading and such, cause Im working on a side-scroller. Here are some file-functions for you to look up on the Microsoft VC++ help thingy, CreateFile(), WriteFile(), ReadFile()good luck.
bad!
quote:I don't know exactly what your problem is. Do you know how to make the whole File I/O stuff or are you a c++ beginner?
access violation or str != NULL
An RPG is a bad thing to start game programming, better start with something like Tetris,Pac Man,...
Use the search function of the Message Board to find more info on File I/O. And if you then have further Questions ask more precise. And please delete the multiple topics with the same name you posted.
Edited by - Jonus on May 4, 2001 3:46:25 PM
I dont''t know if it helps, but if I have heard that
you say "access violaton" i have got an idea:
I also have had "Access violation" and then I read
in my Visual C++ 6.0 Book, and it say that you should
modify your Linker Switch! I think it is the "/ZI"
command in your Linker Options. Modify it to "/Zi" and then try it again !
MFG
FinalBrain
you say "access violaton" i have got an idea:
I also have had "Access violation" and then I read
in my Visual C++ 6.0 Book, and it say that you should
modify your Linker Switch! I think it is the "/ZI"
command in your Linker Options. Modify it to "/Zi" and then try it again !
MFG
FinalBrain
I can''t figure the exact nature of your problem from that post (like all those people who replied before me...) but if you are talking about just reading and writing from/to files in general, this is what I might do (in C):
----------------------------------------------------------
/* data is a variable you declare which is used to read or write. Size of it is up to you - depends on the size of data you are reading or writing. */
unsigned char data; /* or */
unsigned int data; /* or whatever */
/* numObj is the number of consecutive "chunks" you want to read in one go and the size of that "chunk" is sizeObj, in byte. say: */
int numObj=1, sizeObj=1; /* 1 packet of 1 byte */
/* open file in binary format. file is the file pointer
declared by you. filename is a string. */
file=fopen(filename, "rb");
/* locate particular address if necessary using fseek() */
/* offset is number of bytes you want to offset
from the beginning of the file */
fseek( file, offset, SEEK_CUR );
/* read file */
fread( &data, sizeObj, numObj, file );
/* or write to file */
fwrite( &data, sizeObj, numObj, file );
/* close file once you are done with it */
fclose( file );
---------------------------------------------------
I kinda made that up as I went, so I don''t know if it''s 100% accurate (it should be) but you get the idea... If you have NO idea what I''m on about, then you should revise C or C++ file IO functions/classes. C++ IO stream is nicer too, but I''m too much of a moron that I keep going back to good ole C stuff where I can... (Kill me!) It''s one way to do it anyway. It really isn''t hard, even if you use that C method I showed you above. I used only like, what, 5 functions? Open, Seek (if necessary), Write/Read, Close. And you can do whatever you want with those 5.
----------------------------------------------------------
/* data is a variable you declare which is used to read or write. Size of it is up to you - depends on the size of data you are reading or writing. */
unsigned char data; /* or */
unsigned int data; /* or whatever */
/* numObj is the number of consecutive "chunks" you want to read in one go and the size of that "chunk" is sizeObj, in byte. say: */
int numObj=1, sizeObj=1; /* 1 packet of 1 byte */
/* open file in binary format. file is the file pointer
declared by you. filename is a string. */
file=fopen(filename, "rb");
/* locate particular address if necessary using fseek() */
/* offset is number of bytes you want to offset
from the beginning of the file */
fseek( file, offset, SEEK_CUR );
/* read file */
fread( &data, sizeObj, numObj, file );
/* or write to file */
fwrite( &data, sizeObj, numObj, file );
/* close file once you are done with it */
fclose( file );
---------------------------------------------------
I kinda made that up as I went, so I don''t know if it''s 100% accurate (it should be) but you get the idea... If you have NO idea what I''m on about, then you should revise C or C++ file IO functions/classes. C++ IO stream is nicer too, but I''m too much of a moron that I keep going back to good ole C stuff where I can... (Kill me!) It''s one way to do it anyway. It really isn''t hard, even if you use that C method I showed you above. I used only like, what, 5 functions? Open, Seek (if necessary), Write/Read, Close. And you can do whatever you want with those 5.
Here's the C++ way of doing file i/o:
#include "fstream.h" /* use angle brackets, NOT quotes; I just couldn't type them here (because they're interpreted as HTML tags, I think) */
ofstream out_file1("filename.xxx"); // opens a file stream for output to filename.xxx
ofstream out_file2; // declares a file stream for output, but doesn't open up a file yet
out_file2.open("filename.xxx"); // opens the file stream
out_file2.close(); // closes the file stream
out_file1 << "Text" << variable << endl; /* etc., you can use all of the stuff you use with cout, except instead of going on the output stream, it goes onto a file stream */
ifstream in_file1("filename.xxx"); // same as above, except for reading a file
ifstream in_file2; // same as above
in_file2.open("filename.xxx"); // take a wild guess...
in_file2.close();
in_file1 >> variable; // like cin
And that's basically all you need to know. As long as you know cout and cin, it's a cinch.
Edited by - Aprosenf on May 8, 2001 5:53:27 PM
#include "fstream.h" /* use angle brackets, NOT quotes; I just couldn't type them here (because they're interpreted as HTML tags, I think) */
ofstream out_file1("filename.xxx"); // opens a file stream for output to filename.xxx
ofstream out_file2; // declares a file stream for output, but doesn't open up a file yet
out_file2.open("filename.xxx"); // opens the file stream
out_file2.close(); // closes the file stream
out_file1 << "Text" << variable << endl; /* etc., you can use all of the stuff you use with cout, except instead of going on the output stream, it goes onto a file stream */
ifstream in_file1("filename.xxx"); // same as above, except for reading a file
ifstream in_file2; // same as above
in_file2.open("filename.xxx"); // take a wild guess...
in_file2.close();
in_file1 >> variable; // like cin
And that's basically all you need to know. As long as you know cout and cin, it's a cinch.
Edited by - Aprosenf on May 8, 2001 5:53:27 PM
"Access Violatons" are always caused by you accessing a bit of memory (most likely writing to it) that you don''t have rights to. This is usually caused by a bad pointer somewhere. I would double check that:
1) You allocate enough memory for what you are reading in.
2) You are passing the right pointers to functions
Remember that 99% of the time, you have to allocate memory yourself and de-allocate it yourself. Most functions require a pre-allocated buffer to put things in. These functions will normally return the size of the buffer needed if you pass it a 0 for the buffer size parameter (which they all should require).
Double check these things and I am sure you will find the issue.
Good Luck.
Dino M. Gambone
Good judgement is gained through experience. Experience, however, is gained through bad judgement.
1) You allocate enough memory for what you are reading in.
2) You are passing the right pointers to functions
Remember that 99% of the time, you have to allocate memory yourself and de-allocate it yourself. Most functions require a pre-allocated buffer to put things in. These functions will normally return the size of the buffer needed if you pass it a 0 for the buffer size parameter (which they all should require).
Double check these things and I am sure you will find the issue.
Good Luck.
Dino M. Gambone
Good judgement is gained through experience. Experience, however, is gained through bad judgement.
Dino M. Gambone
Good judgment is gained through experience. Experience, however, is gained through bad judgment.
Currently working on Rise of Praxis MUD: http://www.riseofpraxis.net/
ok guys i checked all your postings now and the last one helped me with one of my questions
i dont passed a parameter corectly
see ex.
---------------------------------
---------------------------------------------------
i also wanted to know how you read store your map data.
but you dont understanded me corectly.
thx for the c++ editon but i am not realy interesting in using classes for now.
i saw here many German people ,
because i dont very familar with english and dont realy understand words like chunk and so on, and because i can speake and read/write German Perfectliy it wuold be a nice thing if csomebody writes here something of this stuff in german
it would be much easyer to undestand for me.
thx in advance
(für Fehler und Schrift, haftet der Stift)
i dont passed a parameter corectly
see ex.
---------------------------------
|
---------------------------------------------------
i also wanted to know how you read store your map data.
but you dont understanded me corectly.
thx for the c++ editon but i am not realy interesting in using classes for now.
i saw here many German people ,
because i dont very familar with english and dont realy understand words like chunk and so on, and because i can speake and read/write German Perfectliy it wuold be a nice thing if csomebody writes here something of this stuff in german
it would be much easyer to undestand for me.
thx in advance
(für Fehler und Schrift, haftet der Stift)
.--=Nironics=--.
Quote:
"for mistake and writing, the pencil fastened"?
Erm... my German is crap (I did GCSE German, and that''s all...), so hopefully someone here can speak German to help him out.
But with a bit of luck, translation machine might help. Here goes.
Schreiben Sie bitte in Einfachem Deutsch.
In C, Was Sie benötigen, ist, was ich früher schrieb. ("Was Sie brauchen, was ist den ich früher habe geschrieben"?) Es kommt darauf an fort falls die file ist Text oder binary ("Es hängt an ab, wenn die Datei Text oder Binary ist."?).
Ist ihre Map Text oder Binäres? Wenn Sie mehr Detail wollen, brauchen wir mehr Informationen von Ihnen.
Arg!! Mein Deutsch ist Scheiße!![](smile.gif)
Someone who knows German, Help!
(für Fehler und Schrift, haftet der Stift)
"for mistake and writing, the pencil fastened"?
Erm... my German is crap (I did GCSE German, and that''s all...), so hopefully someone here can speak German to help him out.
But with a bit of luck, translation machine might help. Here goes.
Schreiben Sie bitte in Einfachem Deutsch.
In C, Was Sie benötigen, ist, was ich früher schrieb. ("Was Sie brauchen, was ist den ich früher habe geschrieben"?) Es kommt darauf an fort falls die file ist Text oder binary ("Es hängt an ab, wenn die Datei Text oder Binary ist."?).
Ist ihre Map Text oder Binäres? Wenn Sie mehr Detail wollen, brauchen wir mehr Informationen von Ihnen.
Arg!! Mein Deutsch ist Scheiße!
![](smile.gif)
Someone who knows German, Help!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement