306 – GameMaker: Studio – ini Files

how to make a ini file This is a topic that many people are looking for. star-trek-voyager.net is a channel providing useful information about learning, life, digital marketing and online courses …. it will help you have an overview and solid multi-faceted knowledge . Today, star-trek-voyager.net would like to introduce to you 306 – GameMaker: Studio – ini Files. Following along are instructions in the video below:

“Your game becomes longer you may want na way for players to save. What s s going on in the game and come back to it later nand a very way to do that is using a file type called dot ini. Which nstands for initialize. It usually stores options for setting resolutions for nsound for whatever so that every time someone launches your game.

The ini file nis. Read and then all of those variables are inputted. So the game starts up the nway they wanted it to and how they left it last time. However you can use this to nyour advantage.

When saving other variables for your game. Now. I ve just ngot. Two scripts here that i m using i ve got i and i save and i and i load nbecause that s what we re gonna need to do now.

There s something to understand nabout the structure of an ini file. It has three parts it has a section a key nand. A value now. I m gonna open up an eye on ai file by default game.

Maker saves nit. Under your user name. Op data. Local and then the name of your game.

That nyou re working on in this case. Ini files tut. I i files tut. This is it i m calling nit.

Save da and i here s what one looks like nin the braces. I ve got my section and i ve named it player one and then i ve ngot a key or just score a name and then a value associated with it in this case ni. ve got 50 and my name now they don t normally look like that normally they nwould not exist they would be blank until you actually save information to nthe ini file. But i ve already been playing around with this tutorial now nthat you understand the structure of an ini file.

We can look at how to save and nload the function. I and i open opens up this file behind the scenes while the ngame is running in one step so it s like in perceivable to the player. But it s nnecessary for the computer to open it to start manipulating it like reading or nwriting in this case for saving. We re going to be writing values to this ion nfile and there too you can use one is i and i write string and then i and i nwrite real of course strings.

Forwards and real is for numbers. Each one has nthree arguments..


The first one is the section. If you remember that s the one nin. The braces so you can have multiple sections like this is player one. But nthen you have one that says sound.

And all the sound options one that says nlevel and which enemies are dead. Which ones are alive. Which items you have it s njust. A way of organizing.

It for yourself really then you have the key and this is nkind of like a variable. I m putting that in quotation marks variable for the ini nfile that you re going to be storing some sort of value and this one will nlead a string and i m gonna use my name that s a variable. I have inside game nmaker that is storing the string jack and then for score. I have a real being nstored inside this variable current score.

Then when you re done. It s very nimportant to close the ini file you don t want that left open and holding up nmemory and you also don t want it left open because if you tried to write to a ndifferent ini file. The game will get confused it ll keep writing to the same none got to close it for the game to move on now for loading. There are different nthings.

We can do but i m just gonna concentrate on the simplest thing to nlook at which is i and i open. We re just gonna open it up again nquite simply and now. This is where it s a little different we use the functions ni and i read instead of write once again just string and real and three arguments nagain. The section.

It wants to read from the key. It is then looking for and then ndefault. What this means if you open up the ini file and the game finds that nthere s nothing there then it s got to have something it s got to find nsomething. So what it s going to do is write this value into the i and i and nstore it in a variable that s what i m doing here this is so we can use it in nour game later so if it doesn t find the name jack.

Which is what i ve saved it ll nchange it to no name store that in the variable my name and then we can print nthat to the game. That s running so people know hey no name was found or nwhatever is necessary. It s the same for current score. If no score is found just nmake it zero.

But we still want to be able to read for nso that our ini file is nice clean everything s the way it should be and nremember. We should close it when we re done that s all gonna sound confusing nuntil. We actually look at what s happening in the game. Now i ve only got ntwo objects to keep this simple because we re only looking at the basics.

When my nroom starts. This is an object controller..


It doesn t really do anything but ncontrol all of the kind of like meta code outside of my actual interactive nobjects so when the room starts it s going to declare two global variables. Ncurrent score in my name and i m going to set current score to zero in my name nto jack so every time the room starts that s what will happen then i m just ngonna draw it out to the screen you can pause. It here. If you want to read it but nimma skip through it it s not really that important l.

Will run the i i load s. Nwill run. The i and i save so just load. And save and r will reset.

The room nthat s just some global controls for me to make this tutorial a little easier to nunderstand now in my room. I ve got these object blocks and of course the object ncontroller they don t really do much to be honest. It s just if you click on them nincrement. My score by 10 and then get destroyed.

It s really simple. It s just a nmock up what your game might be doing so if i actually run this game you ll see nthat at the top. I m printing my name and i m printing the current score so let s nstart messing with that let s click on some of these and there we go now my nscore is 40 and if i hit s. That now see in perceivable to you because really nwe re not saving a lot of data.

So you didn t see any kind of like spinning nwheel near my arrow like it s taking a long time to do that s saved so if i nreset the room. Everything will be back to how it was so my name is still jack nwe. ve got zero for the score. Now if i hit l to load.

What will happen nlet me close this high file and open it up again here s what we did we saved my nname and the score remember it was 40 and there it is but if i go back to the ngame and i hit l to load. There we go. 40. Has now been pulled out of that ini file npassed into this variable and printed out to the screen.

Nthere are a few other things we can do there are ways to manipulate the nsections and keys now in this case. I m going to see if i and i key exists. I njust want to know is this here is this key name existing is it in player. 1.

Name nif so i m going to delete it so now if i were to save my file and try to load it nwhen it loads it up it s gonna look inside and say okay now does he have a nname yeah delete it we don t want that section to be there now when it comes to nread string. It s going to pass in the default of my name say this default down nhere. So it s going to give no name to my name. Because i deleted.

My name from the nsave file. So let s see what that looks like now that i ve changed..


It okay. So ni m back in the room. My name is jack my score 0. It s quite simple just the way i nhad it before now.

Let s just start clicking around ok. My score is now 60 nlet s save that so it s saved let s open up the ini file. There it is 60 and my nname is jack perfect. That s what we want however if we hit load.

Well let s reset nthe room. There we go so we reset. The room. Now let s hit load my name does not nexist anymore.

And that s because. I told game maker to look in the diane. I file nand. If it found that the section player 1 and the key name existed just delete nit and then if we can t find something call it no name.

But it still pulled out nthe score. I could do the same thing to score. If i really wanted to in fact. I ncould delete an entire section.

Too so there we go if i delete this entire nsection everything will be gone. So that s that s not just my name now it s nalso the score. And i really any evening that s in there so it s a good way to nkind of reset. A section.

Like let s say you wanted to set everything back to ndefault you can just say list okay open. It up. And just delete the whole section. Neverything s going to be back to default.

If you write in your defaults here so in nthat case. When i run my game. Let s just click on a whole bunch of stuff make all nof them disappear. Okay.

I mean it s safe. So my name is jack..


80. Let s prove nit jack. 80. That s what s in the ini file.

But if i reset the room okay so jack and nzero if i hit load no name and zero. It was already zero. But it s to prove that ni didn t get eighty back i got to zero. So if i open up that i and i file again nthis should blank.

There s actually just nothing there i just deleted everything ninside. I deleted the player one section of course. Although you ve noticed i had nthe default setup right here these don t get saved i m just pulling them into nthese variables whenever i load. But if i save now it will put no name and zero nbut anyway.

It s a good way to kind of reset. Certain sections or certain keys. Ninside your ini file of course this could be expanded upon you can do a loop nany kind of four or while loop. Whatever kind of loop.

You need we even repeat to ngo through certain values and variables in your game. Like which instances are nthere you can check the instance ids of everything store those and their x y npositions. Like it s really complicated. But it is possible or anything really nbut as i said ionize usually an initialization kind of file.

So it nusually holds options and the reason for that is because it s not encrypted nthere s no obfuscation. There s no there s nothing really. It s plain text nyou should be able to just read. It which means anyone can open it and then just nmanipulate it they can change their high score.

They can change whatever and this nis technically true for everything. It s true for android and an ios. I mean you ncould jailbreak or route these devices and then get into the files and change nthem. But the standard person may not do that point being if your ini variables nare not that important you re not scoring high scores like on networks or nwhatever.

It doesn t really matter if players get to change these things. But nif you do then you will need to obfuscate or encrypt and we ll go over nthat in another video. But for now these ” ..

.

Thank you for watching all the articles on the topic 306 – GameMaker: Studio – ini Files. All shares of star-trek-voyager.net are very good. We hope you are satisfied with the article. For any questions, please leave a comment below. Hopefully you guys support our website even more.
description:

tags:

Leave a Comment