Okay for this should of been quick, issue I can't seem to get rid of this error:
QuoteScript 'Game_Actor' line 16: NoMethodError occurred.
undefined method 'nonresistance' for nil:NilClass
In Window_StatusItem, the issue seems to be coming from the first array in the draw_status_resistances method, apparently the @actor.state_probability(i) from the draw_status_list method doesn't like something from $data_states
.name which causes the crash. I've been stuck on this for a day in a half now and this is practically the only thing holding me back. The results is supposed to show a list of states the game has and the only issue is getting the rank percentages to appear.
Script:
class Game_Actor < Game_Battler
def state_probability(state_id)
if $data_states[state_id].nonresistance
return 100
else
rank = $data_classes[@class_id].state_ranks[state_id]
return [0,100,80,60,40,20,0][rank]
end
end
end
class Window_StatusItem < Window_Base
def draw_status_resistances
@pages = []; lines = []; @spacing = 24
AFFINITIES[:states_shown].each do |i|
state = $data_states[i].name
state.each {|line| lines << line}
end
page_numbers = (lines.size / 22) + 1
page_numbers.times {|i| @pages[i] = lines[i*22, 22]}
states_text
end
def states_text
contents.clear
draw_background
draw_status_header(:states_title)
draw_states_list
end
def draw_states_list
dx = 48; dy = 48; dw = calc_ele_width(AFFINITIES[:states_shown])
page = @pages[@page_number - 1]
page.each_index do |i|
rect = item_rect(i)
dx2 = rect.x += dx; rect.y += dy
next if page[i].nil?
begin
draw_icon(page[i], rect.x, rect.y)
rescue
end
contents.font.color = normal_color; contents.font.size = Font.default_size
rect.x += 26; rect.width += dw+20
contents.draw_text(rect, page[i])
contents.font.color = rank_colour(@actor.state_probability(i))
resist = sprintf("%d%%", @actor.state_probability(i))
contents.font.size = 16
contents.draw_text(dx2+dx+44+dw, rect.y, 60, 24, resist, 2)
end
page_footer
end
def rank_colour(amount)
if amount > 100; AFFINITIES[:rank_colour][:srank]
elsif amount > 80; AFFINITIES[:rank_colour][:arank]
elsif amount > 60; AFFINITIES[:rank_colour][:brank]
elsif amount > 40; AFFINITIES[:rank_colour][:crank]
elsif amount > 20; AFFINITIES[:rank_colour][:drank]
elsif amount > 0; AFFINITIES[:rank_colour][:erank]
else AFFINITIES[:rank_colour][:frank]
end
end
def calc_state_width(states)
return $game_temp.status_st_width if !$game_temp.status_st_width.nil?
n = 0
states.each do |state_id|
next if $data_states[state_id].nil?
n = [n, contents.text_size($data_states[state_id].name).width].max
end
$game_temp.status_st_width = n
return n
end
end
Going by the error, I immediately knew you were calling
$data_states[0] somewhere. That brought me to this:
which, according to the help file, means this:
(0 ... ary.size).each {|index| .... }
Try using a
next if i == 0 first and see if that helps with anything.
yes it kind of works, but for some reason it got rid of the first state which I have stun. (not Knockout)
Since I can't really test anything for you, try putting in print statements and see what values your code is running through. Check the index values for your loops and see if it really is running through every value. Print is your best friend when it comes to debugging.
Any exact place I should put it, I put at the line that says page = @pages[@page_number - 1] and it printed me all the of the states that asked for. I don't know where to start. :???:
Just for kicks, try doing
contents.font.color = rank_colour(@actor.state_probability(i+1))
resist = sprintf("%d%%", @actor.state_probability(i+1))
and remove the
next if i == 0.
Well besides the percentages not matching up with the state names. It solved the Stun state disappearance. The percentage issue is that for some reason it's starting with the first state in the database (knockout), instead of aligning each state with it's specific state rank percentage.
(http://db.tt/0hVKVxiS)
[A, B, C, D, E, F]
[100, 80, 60, 40, 20, 0]
If you're not going to draw 'Knockout' at all, then just modify this in your Game_Actor
rank = $data_classes[@class_id].state_ranks[state_id+1]
I have a feeling that you're repeating the same mistake you made in your Bestiary script.
Well actually before I put that in, let me state that a person can put knockout if set in the Module. Sorry for not stating that earlier.
AFFINITIES ={
# The following adjusts what states are shown. Adjust the
# array to meet the state and element ID's.
:states_shown => [2, 3..5, 6, 7..16],
}
This is how I would have done this script.
states_list = []
AFFINITIES[:states_shown].each do |i|
next if $data_states[i].nil?
states_list.push($data_states[i])
end
page_numbers = (states_list.size / 22) + 1
page_numbers.times {|i| @pages[i] = states_list[i*22, 22]}
This way, you have access to the actual state. Now you can use
.name and
.id.
contents.draw_text(rect, page[i].name)
contents.font.color = rank_colour(@actor.state_probability(page[i].id))
resist = sprintf("%d%%", @actor.state_probability(page[i].id))
Sweet :haha: it works finally. Now just have to put in the finishing touches. Thanks again.