[Resolved]Writing status effects and elements for armor

Started by Ryex, December 30, 2008, 12:48:17 pm

Previous topic - Next topic

Ryex

December 30, 2008, 12:48:17 pm Last Edit: December 31, 2008, 07:34:12 pm by Ryexander
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


I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Fantasist

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>}
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Blizzard

December 31, 2008, 07:04:35 am #2 Last Edit: December 31, 2008, 07:09:38 am by Blizzard
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
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

December 31, 2008, 11:40:53 am #3 Last Edit: December 31, 2008, 07:34:47 pm by Ryexander
Thanks people!

Edit: @Blizz I tried you method. but when I call it I still get a "no implicit conversion from nil to integer"
error this is the same problem I was getting before.

EDIT:
Ok fixed that problem but I still get an empty string if I trying to draw an armor's stuff witch is really weird because there is no difference in the two arrays

EDIT: Ok this is just stupid the whole problem is that I for got to add the lines that PRINTED the text if it was an armor *Slaps Face* I'm an IDIOT!! I sorry for wasting your time guys
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />