I'm doing an Equip menu for my new CMS and I can't figure out how to create a text string that contain all the elements, or status effects that a piece of armor protects from. I got it to work for Weapons as you can see below but every time I try to create it for armor it returns a empty string. any Idea what I'm doing wrong?
#-------------------------------------------------------------------------
# * Makes the text for the elements
#-------------------------------------------------------------------------
def make_elem_text_equip(item)
text = ''
flag = false
if item.is_a?(RPG::Weapon)
for i in item.element_set
if flag
text += ', '
end
text += $data_system.elements[i]
flag = true
end
end
if item.is_a?(RPG::Armor)
item.guard_element_set.each_index {|i|
if flag
text += ', '
end
text += $data_system.elements[item.guard_element_set[i]]
flag = true
}
end
return text
end
#-------------------------------------------------------------------------
# * Makes the text for the status effects
#-------------------------------------------------------------------------
def make_stat_text_equip(item)
text = ''
flag = false
if item.is_a?(RPG::Weapon)
for i in item.plus_state_set
if flag
text += ', '
end
text += $data_states[i].name
flag = true
end
end
if item.is_a?(RPG::Armor)
item.guard_state_set.each_index {|i|
if flag
text += ', '
end
text += $data_states[item.guard_state_set[i]].name
flag = true
}
end
return text
end
Why don't you use the same iterator for armors just as weapons? Like
item.guard_element_set.each {|element_id| <code>}
Instead of what you're using:
item.guard_element_set.each_index {|index| <code>}
Basically like this:
string = ''
if x.element_set_array.size > 0
string += $data_system.elements[x.element_set_array[0]]
(1..x.element_set_array.size).each {|i|
string += ', ' + $data_system.elements[x.element_set_array[i]]
}
end
I would actually suggest that you make a method that does that. You simply pass on the element ID array and the elements array.
class Array
def split(delimiter, elements)
string = ''
if self.size > 0
begin
string += elements[self[0]].name
(1..self.size).each {|i|
string += delimiter + elements[self[i]].name
}
rescue
string += elements[self[0]].to_s
(1..self.size).each {|i|
string += delimiter + elements[self[i]].to_s
}
end
end
return string
end
end
i.e. A call for weapon elements would be: "string = weapon.element_set.split(', ', $data_system.elements)".
Or a call for armor guard states would be: "string = armor.guard_state_set.split(', ', $data_states)".
You could use this method for others things as well. I just remembered that this method is called "explode" in PHP. xD