Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411489 Posts in 69377 Topics- by 58433 Members - Latest Member: graysonsolis

April 29, 2024, 12:51:35 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Loading and saving info
Pages: [1]
Print
Author Topic: Loading and saving info  (Read 2176 times)
JasonPickering
Level 10
*****



View Profile WWW
« on: March 30, 2009, 12:25:18 PM »

Al right so I am not sure if this has been talked about on here, but I wondered how people dealt with some of the following things.

1. creating save files

example: if you were creating a zelda game. how do you have the game remember that you have the bow with 10 arrows. Do you guys save and load to an Ini file?

2. loading full levels.

spelunky has its own level format such as Level1.lvl so how does this work. does it check every block in a level and denotes, which part is at each spot. and also if you created a giant world all precdurally, how would you save it.

I know that these problems have several solutions I just wondered how you guys deal with it.

I will probably have other questions, I just wondered.
Logged

ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #1 on: March 30, 2009, 12:37:06 PM »

I use plain text files (but don't name them .txt) to store saved games, level data, and so on. So for both the simplest way is individual plain text files. Using an .ini file isn't a great idea for saved game data, it's normal to use the .ini for game options (screen resolution, fps, controls, or other general options), but not to use it for saved game data.
Logged

JasonPickering
Level 10
*****



View Profile WWW
« Reply #2 on: March 30, 2009, 12:57:39 PM »

is opening and reading from a file like that faster then using an INI file? also can i change the file extension or does it need to be .txt
Logged

ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #3 on: March 30, 2009, 01:00:55 PM »

As I said, it's a good idea not to use .txt, since otherwise people will just open it and change stuff. Just give it any extension you want. I don't use any extension at all.

I don't know about the speed, but because you will only be saving or loading rarely, speed doesn't matter, since it's something that only happens ever few minutes or so. Speed only matters for things done every step, and you won't be saving the game or loading a level 30 times a second or anything. I suspect the speed is identical either way.

If you do use .ini file for save game data it'd be easily altered by any person who wanted to cheat, whereas if you use text files without extensions it'd be harder for them to cheat unless they checked every file and opened it in a text editor.
Logged

Cheesus
Level 0
**


sup.


View Profile
« Reply #4 on: March 30, 2009, 01:57:20 PM »

1: In Game Maker, I used to just save encrypted data to an INI file. Although that's not what INI files are technically for, I found the organization nice. You could very easily save as a text file of sorts, maybe with encrypted information, but it requires more work depending on how you save the data. Basically, you just store the various values in the file and have the game itself process that information. I've also seen people save snippets of code directly, such as "var = 1"

In short, I suppose the most important factors are ease of use and cheating. If you don't mind people easily tampering with variables, go for a plain text file. Otherwise, look into encryption, etc., etc.

2: With a lot of level-reading games like Spelunky, everything is grid based; usually 16 x 16. So level files are just a string of characters that denote different objects. In the game itself, you would probably use something like a for statement to place every 16 blocks from left to right. Once the code reached the end of the room, it would skip to the next 'line' 16 pixels lower. Rinse and repeat. This is just a dumbed down version, though.

Procedurally, there are tons of ways. Some people use algorithms. I think Spelunky's case there are a bunch of pre-made level chunks (such as those snake pits) that are combined together to create an entire level. I could be wrong, though. Gentleman

Logged
JasonPickering
Level 10
*****



View Profile WWW
« Reply #5 on: April 10, 2009, 11:12:20 AM »

so ive been looking around and checking out internal files. so if i want to make a level and I have a saved file that contains

0000000000
0111111110
0111111110
0111111110
0000000000

so how do you get it to read the file and note that each character is a specific thing. basically how do i get it to realize that 100 is one character and then two characters and not the number 100.
Logged

Pishtaco
Level 10
*****


View Profile WWW
« Reply #6 on: April 10, 2009, 01:03:47 PM »

On the first question, I put everything I wanted to save into one of the data structures, then got GM to convert it into a string and saved the string in a text file.
Logged

Gold Cray
Level 10
*****


Gold Cray


View Profile WWW
« Reply #7 on: April 10, 2009, 02:43:06 PM »

so ive been looking around and checking out internal files. so if i want to make a level and I have a saved file that contains

0000000000
0111111110
0111111110
0111111110
0000000000

so how do you get it to read the file and note that each character is a specific thing. basically how do i get it to realize that 100 is one character and then two characters and not the number 100.

Just read the file one character at a time, and subtract 0x30 from each character to get the equivalent number. I don't know the exact syntax for doing it in gamemaker, but in C++ it's just character = fin.get();
Logged
ChevyRay
Guest
« Reply #8 on: April 11, 2009, 12:29:01 PM »

In Game Maker, you can use the function string_char_at(string, position) to get a particular character in a string...

So string_char_at("0001010010", 4) would return "1", because it is the 4th character in the string "0001010010".


To convert a string or a character into a real value, use the real(string) function. For example...

real("1") will return 1.


So one thing you could do would be to save your levels as a string, and when you load them, loop through the level string using these functions to find out what each value was at each position, and creating the correct level object for each on at its respective position in the game room.

That was very summarized, but I don't know what your particular skill level in coding is, so if you can figure it out from that, bravo. If you still need help, feel free to PM me and I'll be glad to whip you up an example Smiley I've got tonnes of different room saving/loading engines kicking around.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic