Hello. i need some help to dissect the script i gonna post below. i did some ruby study months ago. and i did extensively in this week. i got understanding a bit in few areas of ruby. but sadly i cant apply well what i have learn into rgss2...
class Pie_Types
attr_reader :name, :description
def initialize(name, description)
@name = name
@description = description
end
end
#First, let's create our window.
class Window_ChooseSome < Window_Selectable
#We inherited Window_Selectable because it has methods that let us to create
#Selectable Items.
attr_reader :items #We create the items method.
def initialize
super(0, 0, 390, 416)
#Super method. We call this method in every Window creation.
self.index = 0
# Position of the cursor.
self.active = true
# The player can select something.
@items = [Pie_Types.new("Cherry Pie", "A special pie"), Pie_Types.new("Apple Pie", "A tasty pie"), Pie_Types.new("Ultra Death Pie", "Dangerous")]
end
def update
super
# Necessary in order to the window work.
@data = @items
# The items that the player can select.
@item_max = @data.size
#Max number of selectable items.
create_contents
#Also necessary
for it in 0...@data.size
draw_opt(it)
end
# We create the options
# And pass to draw_opt the index of the option
end
def draw_opt(itemm)
rect = item_rect(itemm)
#We create a rectangle instance
self.contents.clear_rect(rect)
# We clear that rectangle
string = @data[itemm].name
# We recover the pie name
rect.width -= 4
self.contents.draw_text(rect.x, rect.y, rect.width, WLH, string)
# We draw the pie name in the window
end
end
class Window_SomeStatus < Window_Base
attr_accessor :item
attr_accessor :item_list #Our especial variables
def initialize(item_list)
super(390, 0, 154, 416) # WE create the window
@item_list = item_list # Create a list with the pie types
@item = 0 # Index variable
end
def refresh
self.contents.clear
draw_information
end
def draw_information
# We draw the description of the text
self.contents.draw_text(0, 0, 140, WLH, @item_list[item].description)
end
end
# Now let's create the scene!
class Scene_ChooseSome < Scene_Base
def start
@window = Window_ChooseSome.new
@status = Window_SomeStatus.new(@window.items)
# We create the Window
end
def terminate
@window.dispose
@status.dispose
# We show the window in the screen
end
def update
super
if Input.trigger?(Input::B)
$scene = Scene_Map.new
end
# If the player presses Esc, we return to the map.
@window.update
@status.item = @window.index
@status.refresh
# We update the window
end
end
wow thats long code there. i take it from a rpg revolution site: learning how to make window selectable.
so far i understand well what exactly happen, until i across this:
#-------------------------------------------------
for it in 0...@data.size
draw_opt(it)
end
# We create the options
# And pass to draw_opt the index of the option
end
def draw_opt(itemm)
rect = item_rect(itemm)
#We create a rectangle instance
self.contents.clear_rect(rect)
# We clear that rectangle
string = @data[itemm].name
#-----------------------------------------
this confusing me. actualy where did those:
it
itemmcame from? what why they are inclosed by parentheses next to method?
and also:
string = @data[itemm].name
why
itemm instead of items ??
i'll be watching this topic everyday to get the answer.
i am sorry for this question. please help explain this thing to me. thank you so much.