Program to edit ini files crashing.
#1
Posted 30 May 2012 - 04:44 AM
Each peice of content has it's own ini file. So I wrote this code to extract the information, run the calculations, and then save the results in the same ini file.
For some reason, it just crashes when it starts up. This script is executed in the objects create event:
var str;
var dex;
var int;
var file;
file = file_find_first(working_directory + "\Items\Equipment\Weapons\*.wep",0)
ini_open(file)
int = ini_read_real("stats","mana",0) / 5
if ini_read_real("info","type",0) != 7 then str = ini_read_real("stats","damage",0) else str = 0
dex = (ini_read_real("stats","aps",0) - 2) / 2 * ini_read_real("stats","damage",0)
if dex < 0 then {str += str*dex; dex = 0}
if ini_read_real("info","type",0) = 7 then dex += ini_read_real("stats","damage",0) * 1.5
str += ini_read_real("stats","defense",0) / 2 + ini_read_real("stats","armor",0) / 5
if str > dex and str > int then
{
str += dex + int
dex = 0
int = 0
}
else if dex > str and dex > int then
{
dex += str + int
str = 0
int = 0
}
else if int > str and int > dex then
{
int += str + dex
str = 0
int = 0
}
ini_write_real("attributes","str",str)
ini_write_real("attributes","dex",dex)
ini_write_real("attributes","int",int)
ini_write_real("info","value",str+dex+int)
ini_write_real("info","bonus",ini_read_real("bonuses","life leech", 0) + ini_read_real("bonuses","mana leech", 0) + ini_read_real("bonuses","mana drain", 0) + ini_read_real("bonuses","move", 0) + ini_read_real("bonuses","damage dealt", 0) + ini_read_real("bonuses","healing", 0) + ini_read_real("bonuses","increased armor", 0) + ini_read_real("bonuses","increased defense", 0) + ini_read_real("bonuses","reduced damage taken", 0) + ini_read_real("bonuses","resistance", 0) + ini_read_real("bonuses","mana regeneration", 0) + ini_read_real("bonuses","healing received", 0) + ini_read_real("bonuses","mana received", 0) + ini_read_real("bonuses","reduced mana costs", 0) + ini_read_real("bonuses","reduced cooldowns", 0) + ini_read_real("bonuses","mana absorption", 0))
ini_close()
file = file_find_next()
while(file != "")
{
str = 0
dex = 0
int = 0
ini_open(file)
int = ini_read_real("stats","mana",0) / 5
if ini_read_real("info","type",0) != 7 then str = ini_read_real("stats","damage",0) else str = 0
dex = (ini_read_real("stats","aps",0) - 2) / 2 * ini_read_real("stats","damage",0)
if dex < 0 then {str += str*dex; dex = 0}
if ini_read_real("info","type",0) = 7 then dex += ini_read_real("stats","damage",0) * 1.5
str += ini_read_real("stats","defense",0) / 2 + ini_read_real("stats","armor",0) / 5
if str > dex and str > int then
{
str += dex + int
dex = 0
int = 0
}
else if dex > str and dex > int then
{
dex += str + int
str = 0
int = 0
}
else if int > str and int > dex then
{
int += str + dex
str = 0
int = 0
}
ini_write_real("attributes","str",str)
ini_write_real("attributes","dex",dex)
ini_write_real("attributes","int",int)
ini_write_real("info","value",str+dex+int)
ini_write_real("info","bonus",ini_read_real("bonuses","life leech", 0) + ini_read_real("bonuses","mana leech", 0) + ini_read_real("bonuses","mana drain", 0) + ini_read_real("bonuses","move", 0) + ini_read_real("bonuses","damage dealt", 0) + ini_read_real("bonuses","healing", 0) + ini_read_real("bonuses","increased armor", 0) + ini_read_real("bonuses","increased defense", 0) + ini_read_real("bonuses","reduced damage taken", 0) + ini_read_real("bonuses","resistance", 0) + ini_read_real("bonuses","mana regeneration", 0) + ini_read_real("bonuses","healing received", 0) + ini_read_real("bonuses","mana received", 0) + ini_read_real("bonuses","reduced mana costs", 0) + ini_read_real("bonuses","reduced cooldowns", 0) + ini_read_real("bonuses","mana absorption", 0))
ini_close()
file_find_next()
}
file_find_close()
#2
Posted 30 May 2012 - 05:54 AM
Anyway, the first problem I see is that you're not putting back the directory name on opening ini files. Remember, file_find functions only return the file name part. (You could immediately notice it if you debug-print the contents of variables.) I also hope you're using GM8.1, or you can't open ini files in other directory.
ini_open(working_directory + "\Items\Equipment\Weapons\" + file)In addition, you have an extra white space in the argument of file_find_first (between "\" and "*.wep") that may cause another problem. Chances are, file_find_first is returning an empty string (as there is no file beginning with a space) thus you're trying ini_open(""), leading into crash.
By the way, you're essentially repeating the same chunk of code twice:
file = file_find_first(...)
ini_open(file);
/*
* Do stuff
*/
ini_close();
file = file_find_next();
while (file != "") {
ini_open(file);
/*
* Repeat the same stuff again
*/
ini_close();
file = file_find_next();
}
file_find_close();That can be merged into one.file = file_find_first(...)
while (file != "") {
ini_open(directory + file);
/*
* Do stuff
*/
file = file_find_next();
}
file_find_close();
Edited by torigara, 30 May 2012 - 07:32 AM.
#3
Posted 30 May 2012 - 05:27 PM
Elaborate what do you mean by "crash". Do you get any error message, or the game stops responding, or whatever else? In the first case you should post the exact error message by copy-pasting.
Anyway, the first problem I see is that you're not putting back the directory name on opening ini files. Remember, file_find functions only return the file name part. (You could immediately notice it if you debug-print the contents of variables.) I also hope you're using GM8.1, or you can't open ini files in other directory.ini_open(working_directory + "\Items\Equipment\Weapons\" + file)In addition, you have an extra white space in the argument of file_find_first (between "\" and "*.wep") that may cause another problem. Chances are, file_find_first is returning an empty string (as there is no file beginning with a space) thus you're trying ini_open(""), leading into crash.
By the way, you're essentially repeating the same chunk of code twice:file = file_find_first(...) ini_open(file); /* * Do stuff */ ini_close(); file = file_find_next(); while (file != "") { ini_open(file); /* * Repeat the same stuff again */ ini_close(); file = file_find_next(); } file_find_close();That can be merged into one.file = file_find_first(...) while (file != "") { ini_open(directory + file); /* * Do stuff */ file = file_find_next(); } file_find_close();
Sweet, I'll look into those things. And yeah I don't get an error message, the program stops responding.. I tried continueing to the next file and calculating once every step instead of all at the creation step, and it didn't crash, but it just saved the first two items without their stats, only attribute requirements,value,and bonus (all the stats the program writes) but it sets them all to 0 instead of what they should be.
But I'll try your suggestions, thanks again.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











