Data Files
Hi all-
I am trying to make a program to load a data file, get information from it, and load that information into my game. So far I've been able to load the data file and print it on the screen.
I also want the data file to be able to be easly edited by the user.
Any ideas for getting the information into my game???
Edited by - King_Over_All on 3/4/00 3:29:57 PM
Can''t anybody help me??? I cant figure this out alone.
Sorry for whining but This is really frustraiting and is bugging me!
Help!
Sorry for whining but This is really frustraiting and is bugging me!
Help!
You''re gonna have to be more specific... It depends on what you want to hold in the data file. If you want it to be edited easily in a text editor, then it comes down to opening a file in text format, and writing text to the file, or just doing it in notepad or something. Then in the game you open it as a text file and read in and parse the text (to parse means to seperate it into meaningful data, such as words and number and stuff). If you want to make an editor, then you can save the files in binary format. Basically, all you need to remember is that a file on disk is nothing more than the same data you would be using in variables, except that you write it to disk.
This probably isn''t very well written, I''m tired now, but good luck and I hope it helps!
------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge
This probably isn''t very well written, I''m tired now, but good luck and I hope it helps!
------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge
Hi - I don''t what sort of compiler you are using, but if you are using a dos compiler you may want to look into functions like fopen, fscanf and fclose. If you are using a windows compiler I''m afraid I can''t help because I''m only just learning that myself
- Daniel
http://sw.mtx.net/daniel/
- Daniel
http://sw.mtx.net/daniel/
- DanielMy homepage
deakin - Just a quick note: You can use fopen, fread and all other stdio functions in Win32 applications. No need for CreateFile
"I think, therefore I am...I think"
"I think, therefore I am...I think"
Hey, I''ve been experimenting with this myself lately, and I''ll share some things I''ve found out.
It is always best to design your file before creating it, so it has coherency - I''m designing an entire system, but thats another story - if you want to allow easy editing by the user, then you''ll want to have some kind of comment structure like double slashes (//) that when you read the file back into your game, they are ignored. This brings up the point that each variable should probably be on one line.
So you''d have a file something like this:
some_option = TRUE // set this to true
another_option = FALSE // set this to false
Thats very basic and simplified, but hopefully it will give you some ideas. Also, you''ve got to remember to use the flags for reading/writing text files, otherwise the file will be gibberish to human eyes.
That format also allows for simple parsing, just read a line into a buffer, and then strcmp // or something - I can''t remember the exact way but that should help you out.
If there''s anything else, I''m sure someone will know.
Take it easy,
-Mezz
It is always best to design your file before creating it, so it has coherency - I''m designing an entire system, but thats another story - if you want to allow easy editing by the user, then you''ll want to have some kind of comment structure like double slashes (//) that when you read the file back into your game, they are ignored. This brings up the point that each variable should probably be on one line.
So you''d have a file something like this:
some_option = TRUE // set this to true
another_option = FALSE // set this to false
Thats very basic and simplified, but hopefully it will give you some ideas. Also, you''ve got to remember to use the flags for reading/writing text files, otherwise the file will be gibberish to human eyes.
That format also allows for simple parsing, just read a line into a buffer, and then strcmp // or something - I can''t remember the exact way but that should help you out.
If there''s anything else, I''m sure someone will know.
Take it easy,
-Mezz
Thanks for responding!
Qoy - I want to use text files. But I''m still not sure how to seperate the data! Should I use keywords, or characters defining what the line will contain?
Deaken - I''m using DJGPP, and have already opened the file and printed the information to the screen. My trouble is getting the data into the game!
Mezz - Thanks. I''m still trying some stuff, but I''m thinking that I''m probably going to use characters to show what kind of data is in the rest of the line.
For instance:
# - would be a comment
& - would be a name
() - would be placed directly under the name to store numbers and data
----
to all of you
Thanx
Qoy - I want to use text files. But I''m still not sure how to seperate the data! Should I use keywords, or characters defining what the line will contain?
Deaken - I''m using DJGPP, and have already opened the file and printed the information to the screen. My trouble is getting the data into the game!
Mezz - Thanks. I''m still trying some stuff, but I''m thinking that I''m probably going to use characters to show what kind of data is in the rest of the line.
For instance:
# - would be a comment
& - would be a name
() - would be placed directly under the name to store numbers and data
----
to all of you
Thanx
Just to let you know, what you said in your last post is exactly what I would do.
To get the data into your game you would copy the varibles you have taken from the data file to the variables used in the game. Of course, this gets a bit harder when you need to store a large amount of data in which case you may need to use an array or a linked list.
-Daniel
PS: Thanks for the info Staffan, I wasn''t quite sure about that
-Daniel
PS: Thanks for the info Staffan, I wasn''t quite sure about that
- DanielMy homepage
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement