Using Ini's, and strings
From YoYoGames Wiki
Contents |
INI File Usage
Have you ever played a game where it asks for your name and displays it throughout the game? Well, I bet you want to know how to do it too. To do this you'll need to make an ini file, and you'll need to get familiar with string functions.
Creating The Ini
An ini file is used to store and use information. An ini file is setup with a header, and keys. Here is an example of an ini file:
[Heading] Key = 100
Now you can always customize the ini to say whatever you want, it doesn't really matter what it says though.
[Levels] Mining = 1 Attack = 1
But in our case, you'll want to make an ini that goes like this:
[PlayersInfo] Age=0 Name=" "
To make ini's, just open up the program notepad, then type in that, then go to save as, and save it as ini.ini
Getting The Name
To get the name you'll need to use the string function, and a few variables. To get the age, you'll need to do the same thing, or you can use an interger.
Here's how you'd get them:
global.playername = get_string('What is your name?',)
global.playerage = get_integer('What is your age?',)
Saving The Info
Now, you need to save the info into an ini To do this, you'd put:
ini_open('ini.ini')
ini_write_string("PlayerInfo","Name",global.playername)
ini_write_real("PlayerInfo","Age",global.playerage)
ini_close()
Loading Your Information
Now, at your game start, you'll want to load the name. To do this you'll need to put in:
ini_open('ini.ini')
global.playername = ini_read_string("PlayerInfo","Name","")
global.playerage = ini_read_real("PlayerInfo","Age","")
ini_close()
Using Your Info
Now to use your info in the game, you'll just use the string functions. For example:
show_message(string('Hello')+string(global.playername))†
†Notice how variables are not in ('')

