Klearophlidrophacy
Member
In addition to the fact that it's 4 in the morning, I'm still a beginner scripter, and as such I can't quite seem to get a grasp on what a certain portion of this script is doing. It's RPG Advocate's manual EXP table override.
The method correct_malformed_input is the one that's... Interesting to me.
After a couple of tests, I found out that what it does is change the "list" array to contain the value that's to the right of the level. Erm, if you haven't seen this before, it's a little better explained viewing the sample text document.
I generally understand what the rest of the code is doing (to an extent), I'm just completely lost on how exactly this method is doing its job.
So, anyone wanna help out a newbie understand RGSS a bit better? ^_^;
EDIT: AH!! I just remembered there's a sticky just for asking about existing RGSS scripts. >_<; Sorry, quite a bit tired... I'm not sure, should this post be deleted/merged with that topic, or is it fine as it is...? I guess that's what the mods are here for...
Code:
class Game_Actor < Game_Battler # New Methods
# -----------------------------
def get_exp_list_from_file(filename)
begin
if @exp_file_error
return
end
f = File.open(filename)
list = f.readlines
list = correct_malformed_input(list)
if @exp_file_error
return
end
for i in 0..list.size - 1
list[i] = list[i].to_i
end
list = correct_erroneous_data(list)
for i in list.size..100
list[i] = 0
end
list.unshift(0)
@exp_list = list
rescue StandardError
s1 = "Unrecoverable error while reading " + @name + "'s EXP list.\n"
s2 = "Experience curve declared in the database will be used instead."
print(s1 + s2)
@exp_file_error = true
retry
ensure
if f != nil
f.close
end
end
end
# -----------------------------
def correct_malformed_input(list)
lines_to_delete = []
if list.size == 0
s1 = "Warning: " + @name + "'s experience requirement file is empty. "
s2 = "Experience curve declared in the database will be used instead."
print(s1 + s2)
@exp_file_error = true
return
end
for i in 0..list.size - 1
delflag = false
for j in 0..list[i].size - 1
if list[i][j] != 10 && list[i][j] != 32 &&
!(list[i][j] >= 48 && list[i][j] <= 57)
delflag = true
end
end
if list[i].size == 1 && list[i][0] == 10
delflag = true
end
if delflag
lines_to_delete.push(list[i])
end
end
if lines_to_delete != []
for i in 0..lines_to_delete.size - 1
list.delete(lines_to_delete[i])
end
end
for i in 0..list.size - 1
while list[i].include?(32)
list[i].slice!(0)
end
end
return list
end
# -----------------------------
def correct_erroneous_data(list)
warnings = ""
wrong_exp = false
if list[0] != 0
list[0] = 0
s1 = "Warning: " + @name + "'s experience requirement for level 1 "
s2 = "must be zero. Automatically correcting error.\n"
warnings += s1 + s2
end
if list.size < $data_actors[@actor_id].final_level
if list.size >= 2
value = list[list.size - 1] - list[list.size - 2]
for i in list.size..$data_actors[@actor_id].final_level - 1
list[i] = list[i-1] + value
end
else
list = []
for i in 0..$data_actors[@actor_id].final_level - 1
list[i] = i
end
end
s1 = "Warning: Fewer levels than " + @name + "'s maximum level have "
s2 = "been declared. Creating temporary substitute values.\n"
warnings += s1 + s2
end
if list.size > $data_actors[@actor_id].final_level
new_list = []
for i in 0..$data_actors[@actor_id].final_level - 1
new_list[i] = list[i]
end
list = new_list
s1 = "Warning: More levels than " + @name + "'s maximum level have "
s2 = "been declared. Ignoring excess declarations.\n"
warnings += s1 + s2
end
for i in 1..list.size - 1
if list[i] <= list[i-1]
if i == list.size - 1 && list.size != 2
diff = list[i-1] - list[i-2]
list[i] = list[i-1] + diff
elsif i == list.size - 1 && list.size == 2
list[i] = 10
else
if list[i+1] > list[i-1]
diff = list[i+1] - list[i-1]
list[i] = list[i-1] + diff / 2
else
list[i] = list[i-1] + 10
end
end
wrong_exp = true
end
end
if wrong_exp
s1 = "Warning: One or more experience requirements for " + @name + " "
s2 = "is less than or equal to the previous level's requirement. "
s3 = "Creating temporary substitute values."
warnings += s1 + s2 + s3
end
if warnings != ""
print(warnings)
end
return list
end
The method correct_malformed_input is the one that's... Interesting to me.
Code:
def correct_malformed_input(list)
lines_to_delete = []
if list.size == 0
s1 = "Warning: " + @name + "'s experience requirement file is empty. "
s2 = "Experience curve declared in the database will be used instead."
print(s1 + s2)
@exp_file_error = true
return
end
for i in 0..list.size - 1
delflag = false
for j in 0..list[i].size - 1
if list[i][j] != 10 && list[i][j] != 32 &&
!(list[i][j] >= 48 && list[i][j] <= 57)
delflag = true
end
end
if list[i].size == 1 && list[i][0] == 10
delflag = true
end
if delflag
lines_to_delete.push(list[i])
end
end
if lines_to_delete != []
for i in 0..lines_to_delete.size - 1
list.delete(lines_to_delete[i])
end
end
for i in 0..list.size - 1
while list[i].include?(32)
list[i].slice!(0)
end
end
return list
end
After a couple of tests, I found out that what it does is change the "list" array to contain the value that's to the right of the level. Erm, if you haven't seen this before, it's a little better explained viewing the sample text document.
I generally understand what the rest of the code is doing (to an extent), I'm just completely lost on how exactly this method is doing its job.
So, anyone wanna help out a newbie understand RGSS a bit better? ^_^;
EDIT: AH!! I just remembered there's a sticky just for asking about existing RGSS scripts. >_<; Sorry, quite a bit tired... I'm not sure, should this post be deleted/merged with that topic, or is it fine as it is...? I guess that's what the mods are here for...