The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: shintashi on November 25, 2010, 06:41:56 PM

Title: Modified Skill list cloning same numbers?
Post by: shintashi on November 25, 2010, 06:41:56 PM
I was trying to create a skill level system independent to actors, but even though the actors may have different skill levels, I can't get any skill levels to display past the first listed skill, more specifically, whatever my first listed skill's level is for that actor, all their other skills display the same skill level in the menu.


player 1
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg819.imageshack.us%2Fimg819%2F6845%2Frmxps1.jpg&hash=5b0ade8b3e6c10487ed27c71962524082c596b7e)

player 2
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg18.imageshack.us%2Fimg18%2F9177%2Frmxps2.jpg&hash=91dfa7ffc34f64b493f5c482b9109d2174cd1e48)


Skill id in data base:
mythology: 10
pyrokinesis: 19
bird killer: 73


Quote# testing ------------------------------------------------------
 
  def mark
    skill = @data[index]
    m = skill.id
    @actor.skill_levels = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
    sk = @actor.skill_levels[m]
  return "MU " + sk.to_s
  end
Quote
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    skill = @data[index]
    if @actor.skill_can_use?(skill.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(skill.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 204, 32, skill.name, 0)
   # self.contents.draw_text(x + 232, y, 48, 32, skill.sp_cost.to_s, 2)
        self.contents.draw_text(x + 218, y, 60, 32, mark.to_s, 2)
  end


I don't understand the draw_item(index) enough to fix it.
Title: Re: Modified Skill list cloning same numbers?
Post by: modern algebra on November 25, 2010, 11:54:59 PM
The problem is that you are calling the method index in your mark method. The index method returns the index of the skill that the cursor is currently over. Since all of the skills are refreshed at once, mark will return the level of the one currently selected, rather than the index of the one you are trying to draw. All you need to do to fix it is pass the index variable from draw_item to the mark method.
Title: Re: Modified Skill list cloning same numbers?
Post by: Shinami on November 26, 2010, 12:01:01 AM
Might I suggest printing the variables via "p variable_here" to double check their contents?(Doing this will most certainly prove Modern is correct) Also, @actor.skill_levels looks like it's a static(READ:unchanging) variable. So, why are you continuously storing the same data in it on each function call of "mark"? Shouldn't that be in the initialization function of the Game_Actors class with it set as an attr_reader:??? I say Game_Actors because @actor is a common variable name that Enterbrain has associated with the class and you'll see it all through out the status, skill, and equipment windows.

It's your call where you put things but I personally find it easier to define and setup my actor variables in the init. function of Game_Actors. =)
Title: Re: Modified Skill list cloning same numbers?
Post by: shintashi on November 26, 2010, 03:03:59 AM
Quote from: modern algebra on November 25, 2010, 11:54:59 PM
The problem is that you are calling the method index in your mark method. The index method returns the index of the skill that the cursor is currently over. Since all of the skills are refreshed at once, mark will return the level of the one currently selected, rather than the index of the one you are trying to draw. All you need to do to fix it is pass the index variable from draw_item to the mark method.

How do I pass the index variable to the mark method?


Quote from: ShinamiIt's your call where you put things but I personally find it easier to define and setup my actor variables in the init. function of Game_Actors. =)
I was just testing the number displays on the fly, skill_levels is going into main once the display functions properly, and then it will be dynamic. :)


Title: Re: Modified Skill list cloning same numbers?
Post by: shintashi on November 26, 2010, 04:54:11 AM
I think I figured it out. MA said I needed to do was pass drawn item's index variable to the mark method. Instead I tried putting the stuff in the mark method inside the draw item index...
Quote
  def draw_item(index)
    skill = @data[index]
    if @actor.skill_can_use?(skill.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
 

    m = skill.id
    sk = @actor.skill_levels[m]
  mark = "MU " + sk.to_s
   
   
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(skill.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 204, 32, skill.name, 0)
   # self.contents.draw_text(x + 232, y, 48, 32, skill.sp_cost.to_s, 2)
        self.contents.draw_text(x + 218, y, 60, 32, mark.to_s, 2)
  end