The Game.ini file contains configuration stuff that the rpg maker engine uses. You can see in this screenshot I already put two settings of my own here.
The first one, SkipCutscene, returns a number.
The second one, Codename, returns some text.
Here is what to do if you want to call a number:
First open the Game.ini file and write in the SkipCutscene=1 line of the screenshot, or whatever else you want your setting to be called.
next open the script editor in your game project.
Paste GAME_INI_ENTRY = /^SkipCutscene=(.+)$/
anywhere as long as it isnt under a class. This will be the name of the setting you want to check. The funny symbols around it are regex, which tell the game how to read this text. This is often used in other scripts to read code in notes or comments.
Now go to Game_Interpreter and paste in this:
def skip_cutscene
saved_num = nil
File.open('Game.ini') { |f|
f.each_line { |l|
next unless l.valid_encoding?
GAME_INI_ENTRY.match(l) { |m|
saved_num = m[1].to_i
break
}
}
}
return saved_num rescue 0
end
This opens the Game.ini file and looks through each line, skips any it can't properly read, (like text with ä, ö or ü letters),
and looks for any matches with the GAME_INI_ENTRY text.
If it does find a match, it saves it in the saved_num variable and turns it into an Integer. (basically a number with no decimals.)
Then it saves the number in the saved_num variable. If it gets nothing, it simply returns a 0.
Considering this tutorial is about how to make all of this happen through a script call, this code has to be put in the Game_Interpreter class, so that one can simply call the method name.
Like this:
Here in $game_variables[1] = skip_cutscene
the returned number of the skip_cutscene method gets saved in a variable.
Then a conditional branch checks if the variable is 0. If not, it will skip that inside the conditional branch entirely.
If you want to make it get text instead, do this:
Paste GAME_INI_NAME = /^Codename=(.+)$/
just like in the previous example.
Open the Game.ini file and write in Codename=Deleted Donut
or whatever else you want it to be called.
Next inside the Game_Interpreter class:
def get_codename
saved_name = nil
File.open('Game.ini') { |f|
f.each_line { |l|
next unless l.valid_encoding?
GAME_INI_NAME.match(l) { |m|
saved_name = m[1].to_s
break
}
}
}
return saved_name rescue ""
end
This pretty much does the same thing as the number code, except turning the end result into a string.
An example for using this method is this:
And now an event read text out of the game.ini file.
4 comments