RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[solved]Better way of making Window Selectables?

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 82
We learn by living...
here's the selectable window I made that displays actors (I chopped out the frivolous stuff for brevity)

Code: [Select]
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:

Code: [Select]
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.

« Last Edit: January 16, 2011, 01:11:07 AM by shintashi »

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
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:

Code: [Select]
$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.

***
Rep:
Level 82
We learn by living...
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. ^^