Page 1 of 1

Different files in games.

Posted: Wed Dec 18, 2002 1:48 pm
by Joey
This may be a stupid question to you guys, but i dont get this. in games, there are other files, they could be like .stz or . whatever. how do programmers make these files and then tell the .exe file to open them and read them a certain way? im just confused about how this works. instead of like .cpp files, there will be a different type of file. im confused.

Re:Different files in games.

Posted: Wed Dec 18, 2002 2:57 pm
by jrfritz
Well, like SCI, the program (.exe) reads these files. A programmer might even make his own programming languages to make this files, or use a program from a 3rd party.

Re:Different files in games.

Posted: Wed Dec 18, 2002 4:23 pm
by ark
A game reads data from a file using File I/O calls, which are specific to whatever programming language / library you're using to write your program. With C, it's fread. With C++, it's ifstream. If you're using the Windows API with C or C++, you can use ReadFile (I think). If you're using MFC with C++, you can use the CFile class.

You can store anything in a file that you can store in RAM. There's nothing particularly complicated about it.

Re:Different files in games.

Posted: Wed Dec 18, 2002 8:21 pm
by gxl117
Yes, I agree joel.
use those function in library you can hold anything in any type file!!:)

Re:Different files in games.

Posted: Wed Dec 18, 2002 9:43 pm
by Andrew_Baker
Remember, Joey, all a file contains is 0s and 1s. It is only how a file is handled that determines whether it's text or graphics or a big chunk of hexadecimel. As far as programmers making up their own file extensions, you'll notice this convention being used in your own AGI project. They are often labelled thusly so the executable properly identifies them. Many videogames have game levels in files with the name of the level followed by, maybe a .lvl extension. For games with add-on levels and whatnot, this allows the game engine to look at it and know that it's an added level and not a sprite tile set.

Re:Different files in games.

Posted: Thu Dec 19, 2002 1:38 pm
by Joey
yah i mean, do you code the program to read . whatever files when this happens or whatever? you cant save a source file as like .psk and then expect the .exe to read that file as code right? i really dont understand this. :-[

Re:Different files in games.

Posted: Thu Dec 19, 2002 4:09 pm
by ark
a file extension doesn't really mean anything, Joey. Primarily, it's used by Windows so that it knows when you double-click on a .exe file, it should try to run it as a program, or when you double-click on a .doc file, it should run Microsoft Word and tell Word to load the file you clicked. It's also used to tell which icon should appear beside the file. But there's nothing to stop you from trying to open any type of file using any program. The only reason it doesn't work is that the program expects the bytes in the file to be a certain way, and it doesn't know how to work with them any other way.

All files are made up of nothing but bytes. The only difference is how the program that reads the file chooses to interpret the bytes. Notepad interprets the bytes as text, but that may not be what the file is supposed to be at all, for example if it ends in a .exe extension. That's why opening a .exe in Notepad or Wordpad will show you nothing but garbage. The contents of the file actually do mean something, but to Notepad they mean garbage and to Windows they mean a runnable program.

Yes, you could get a .exe to interpret a .psk file as code. Windows won't do that because it expects executable files to end in .exe, but if you rename a .exe file so that it ends in .psk, it will still contain the same data. If you double-click on it, Windows won't run it, but that's only because Windows determines the type of a file by its extension.

Re:Different files in games.

Posted: Thu Dec 19, 2002 7:24 pm
by Andrew_Baker
If you want to get really deep, try playing around with Classic Mac Resources. Now, Classic Mac really doesn't use file extensions except to indicate when a file has been compressed (sit) and hex-archived (hqx) or whatnot. All of the details that are determined automagically by Windows by the file extension are embedded in the resource fork in a Mac environment. So, in this case, the icon graphics, how the program should be executed, and even executable code can be embedded in the file descriptor. Why? Well, on my Windows Desktop, every time I install a new app that can view graphics files, all of my graphical programs get into a war over which is the default. The same with any audio or video file, so I'm constantly having to reset my defaults and run into many different consistency problems when I'm trying to open files for browsing. With the Resource Fork, you can determine how a program is opened by editing the Fork. It won't default to anything other than the app you told it to default to. Also, in Windows, I have my icons constantly changing to the viewer's default. In Mac, the icon of a graphics file is often a thumbnail of the graphic, allowing me to immediately determine its content. I think that's just neat :D

Re:Different files in games.

Posted: Mon Dec 23, 2002 7:54 pm
by Joey
ok. thanks guys.