The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: shintashi on January 15, 2011, 05:58:13 PM

Title: [solved]Better way of making Window Selectables?
Post by: shintashi on January 15, 2011, 05:58:13 PM
here's the selectable window I made that displays actors (I chopped out the frivolous stuff for brevity)


class Window_3 < Window_Selectable
  def initialize
    super(0, 0, 440,380)
    self.contents = Bitmap.new(width-32, height-32)
  refresh 
  @column_max = 1
  self.active = true
    self.index = -1
  end
   
     def refresh
       self.contents.clear
     @item_max = $game_party.actors.size
     for i in 0...$game_party.actors.size
      x = 0
      y = i * 150
      if i >= 2
        x=250
        y -= 300
      end     
      actor = $game_party.actors[i]
    #BLOCK 2.0
      self.contents.font.color = text_color(6)
      self.contents.draw_text(x+5, y, 200, 32, actor.name)
      offset_x=contents.text_size(actor.name).width+10
        self.contents.font.color = normal_color
self.contents.draw_text(5+x+offset_x, y, 200, 32, "(Level " + actor.level.to_s + ")")
      draw_actor_hp(actor, x+5, y+32)
      draw_actor_sp(actor, x+5, y+64)
  self.contents.font.color = system_color
      self.contents.draw_text(x+200, y+64, 200, 32, "Experience")
  self.contents.font.color = normal_color
  self.contents.draw_text(x + 285, y+64, 84, 32, actor.exp_s + " /")
xp_l = (actor.exp_s.length * 5)
  self.contents.draw_text(x + 320 + xp_l, y+64, 84, 32, actor.next_exp_s)
     
     
    end
  end

 
#--------------------------------------------------------------------------
# * Cursor Rectangle Update
#--------------------------------------------------------------------------
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
    else
      self.cursor_rect.set(0, @index * 150, self.width - 32, 96)
    end
  end 
 
end #end window 3


So this window selects an actor, and executes (whatever) when I hit the spacebar. Right now, what I'm executing is this mess:


if Input.trigger?(Input::C)

if @window_3.active == true
   p @window_3.index
   m = @window_3.index
   l = $data_system.party_members[m]
   p $game_actors[l].name
end

end


Clearly I don't know what I'm doing because "Window 3 index" is only spitting out the cursor order (0,1,2,..etc) and I'm trying to directly access the actor number, which might look more like (12,5,9..etc).

While my above code  (m = ... l = ..[m]) works, I have a feeling there's a more direct way of getting my actor numbers... because I suck at coding ruby and even I think my workaround looks like crap.

Title: Re: Better way of making Window Selectables?
Post by: modern algebra on January 15, 2011, 09:16:55 PM
Stop going to $data_system.party_members - that will only spit out the initial party and won't be changed if, for instance, another party member has since been added or removed. Go to $game_party.actors and that will spit out an array of the actors currently in the party, which I believe is what you want, as you can then do:

$game_party.actors[@window_3.index]

and that will throw back the Game_Actor object for the selected actor. That is a good way to do it in this case, as the commands of the window are already accessible through a global variable in that way.

I don't really know what your title is referring to, as I don't see why you need a better way of making them. The Window_Selectable class is a useful superclass for that kind of object, but it doesn't limit you in any way - if something is unhelpful for the particular class you are making, just overwrite it.
Title: Re: Better way of making Window Selectables?
Post by: shintashi on January 16, 2011, 01:10:44 AM
overwriting something from another class is still rather new to me (last week), but your script definitely trimmed down the problem from 5 lines to 3 lines for what I'm doing. ^^