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.
[VX] please help explain the script(newbie)

0 Members and 1 Guest are viewing this topic.

**
Rep:
Level 55
RMRK Junior
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...

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

came 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.  :lol:
« Last Edit: December 26, 2012, 12:31:19 AM by irfanganu »

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Best IRC Quote2014 Zero to Hero2014 Most Missed Member2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
The words contained in parentheses next to the method names are called 'arguments'. They are basically local variables defined for the duration of the method. They must be passed to the method when it is called. If an argument is defined, it can be used like any other variable in the method. The way to pass an argument is shown here:
Code: [Select]
class Example
  def tutorial(arg1, arg2, arg3 = false) # Defines the method, and the arguments required. As seen in the next line, arg1 and arg2 are Numerical and arg3 is a boolean.
    x = arg3 ? arg1 + arg2 : arg1 * arg2 # Defines a variable based on the given arguments.
    return x # Returns the variable previously defined.
  end
end

n = Example.new
print n.tutorial(1, 2, true) # => This will display the number '2'. The arguments we provided told the 'tutorial' method to multiply 1 and 2. It multiplied because we set the method to add if the third argument is false or multiply if it is true.
print n.tutorial(2, 3, false) # => This will display the number '5'. The arguments we provided told the method that the numbers we are using are 2 and 3, and that we are adding because the third argument is false.
print n.tutorial(4, 4) # => This will display the number '8'. Note that we did not provide a third argument. You may have seen earlier that we wrote the third argument of the method as 'arg3 = false'. This means the argument will default to 'false' if nothing else is provided. So the script added 4 and 4.

Hope that helped give you an understanding of arguments.
it's like a metaphor or something i don't know

**
Rep:
Level 55
RMRK Junior
i think i get the point abit.

Pacman, is it safe to assume that an arguments next to method mostly used as a 'box' (the box's value/number keeps changing as the reading of data, oh well  looping  inside an array?) 

example:

for number_of_box in 0...@data.size
 start_counting (number_of_box)
end

where if the method named start_counting functioning as to read everything inside an array,
then the arguments number_of_box is used to store a temporary-changing value, start from 0 till max number of array.

sorry for noob question  ;D


update:

gosh i read from ruby guide here http://mislav.uniqpath.com/poignant-guide/book/chapter-3.html
saying arguments is like supplying an extra information for methods to work.
« Last Edit: December 27, 2012, 12:04:04 AM by irfanganu »

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Best IRC Quote2014 Zero to Hero2014 Most Missed Member2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
If I understand what you're saying, then I think you're right in what you're talking about.
it's like a metaphor or something i don't know

**
Rep:
Level 55
RMRK Junior
i think i try script some window selectable. to test it out..lol

i refer here back after finish this

**
Rep:
Level 55
RMRK Junior
ok i'm done doing my personal version of window selectable. here are the result:





so here are the codes with some questions(colored inside). Pacman, if you have time to answer my question, please reply here.
i really want to learn this rgss2  :) it took me 5 days to really understand what happen inside this script by doing some research on google and referring to F1 help file. also great help from IXFURU. thank you. if anyone reading this topic that wanna give advices, i really appreciate it.

Code: [Select]
#-------------------------------------------------------------------------
# now i gonna make a fruits grocery(because i love fruits)
#
#----------------------------------------------------------------------
class Grocery_Store #this is my fruits grocery
 
  attr_reader :name, :fruits_info #information that i want to show to visitor(name of fruits and its descriptions)
                                   #here i use 'fruits' because i think its show multiple lists at once.
  def initialize (name , fruits_info) # this is arguments right? (name,info)
    @name = name #assingn it to instance variable
    @fruits_info = fruits_info #same as above
  end
end
#--------------------------------------------------------------------
#
#now i gonna make a list for buyers to choose!
#
#---------------------------------------------------------------------

class W_Select_FruitName < Window_Selectable # so this is my selection of fruits.
 
  attr_reader :our_fruits #i wonder why this is only to read the info in array?
                          # i test with attr_accessor and its works same.
 
  def initialize
    super(0,0,200,200) # so we make the selection window. it will contain list of fruits.
    self.index = 0 #this is our default cursor position. 0 indicate its 1st in list.
    self.active = true # this allow us to move cursor.
    @our_fruits = [Grocery_Store.new("Durian", "Raja Buah"), Grocery_Store.new("Rambutan","Sangat Manis"), Grocery_Store.new("Papaya","Masih putik")] #my list of fruits(name,info)
  # we Grocery_store.new because we have to solidfy the grocery stores right?
  end
 
 
  def update # actually i dont know where the 'update' come from. just following the tutorial.
    super
    @data = @our_fruits #this is from the array.
    @item_max = @data.size #this i know its max item in array we offer(inherit from window selectable rite?)
    create_contents #is this nessesary? i cancel this out and the script still works. wierd?
    for arg1 in 0...@data.size #ok so i think the arg1 start to increase or decrease in number as we move our cursor from durian till papaya. am i right?
      show_fruit_name(arg1) #so i make the method. its to show only the name of fruits in array, not the info. am i right?
    end
  end
 
   
  def show_fruit_name(arg2) #so i define the method. its to show the name of fruits. actually i dont understand why i use arg2 here.
    rect = item_rect(arg2) #inherit from window selectable right? this line here i just follow the tutorial..
    self.contents.clear_rect(rect)# why do we need to clear the rect? also from where did the .clear_rect refers to?
    string = @data[arg2].name # this is our main reason i think. the function of this window selecatble is to read the name of fruits as its .name  Am i right?
    self.contents.draw_text(rect.x, rect.y, rect.width, WLH, string) #string is refer to above. i not sure where did rect.x, rect.y, rect.width and WLH came from. just follow the tutorial.
  end
end

#-------------------------------------------------------------------
#
#so now we gonna make windows to display our fruits info
#
#----------------------------------------------------------------------

class W_Fruit_Info < Window_Base #so this window is to draw information of fruits.
 
  attr_accessor :fruit_info #instead to "fruits_info", i name it "fruit_info" because we draw information of fruits one by one right? singular is no 's'.. lol
  attr_accessor :fruit_list # this is refering to fruit that we select one by one.
 
  def initialize(fruit_list)
   super(205,0,200,200)
    @fruit_list = fruit_list
    @fruit_info = 0 # this is index position i believe.
  end
 
  def refresh
    self.contents.clear
    draw_info_fruit #method below we gonna show the info of fruits.
  end
 
  def draw_info_fruit
    self.contents.draw_text(0,0,180,WLH,@fruit_list[fruit_info].fruits_info) #this is why the reason we make this window. its to read the information of fruits inside the array.
  #but i dont understand how did .fruits_info can be read in this class while its actually from other classes(i refer to class Grocery_Store)
  end
 
end


class Scene_Grocery_Store < Scene_Base
 
  def start
    @window = W_Select_FruitName.new
    @status = W_Fruit_Info.new(@window.our_fruits) #hmm... this one i not sure (@window.our_fruits). i just follow the tutorial. plese explain why its need to be writen in this line.
    # 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.fruit_info = @window.index
    @status.refresh
    # We update the window
  end
 
end

 
« Last Edit: December 27, 2012, 03:30:25 AM by irfanganu »

***
Rep:
Level 75
What the...?
@irfanganu

Quote
#i wonder why this is only to read the info in array?
# i test with attr_accessor and its works same.

attr_accessor is both an attr_reader AND attr_writer.

You use attr_reader when you just want to get the information from a class's instance variable
You use attr_writer when you want to be able to change the information in a class's instance variable.
You use attr_accessor when you have the need to do both.

Quote
why do we need to clear the rect? also from where did the .clear_rect refers to?

This is just to ensure there is nothing in the rect.  That way, when the window refreshes, you don't get things written on top of each other.

Quote
#is this nessesary? i cancel this out and the script still works. wierd?

If you look at what the 'create_contents' method does, you will see that it does this:

Code: [Select]
  def create_contents
    self.contents.dispose
    self.contents = Bitmap.new(width - 32, height - 32)
  end

I didn't understand this at first either.  Someone explained it to me though.  If you have a window that has changing contents, based on index for example, you need to call this method to dispose of the old info before placing new contents in.  Once again, without this, you risk drawing things on top of each other.

Quote
#this is why the reason we make this window. its to read the information of fruits inside the array.  #but i dont understand how did .fruits_info can be read in this class while its actually from other classes(i refer to class Grocery_Store)

Code: [Select]
@fruit_list = fruit_list
 

That's how it can be read.  When you created the window with this in the initialize method:

Code: [Select]
  def initialize(fruit_list)

You accepted arguments for fruit list from the scene:

Code: [Select]
@status = W_Fruit_Info.new(@window.our_fruits)

The argument you gave was from the other window's instance variable 'our_fruits'.


I hope this helps you.  Sometimes, when learning you just have to spend a lot of time reading methods of default scripts AND the built-in methods from the Help files.   If you don't understand where an object gets a method, right click the scripts LIST and 'find' the method.  You'll be surprised at how many of your own questions can be answered in this way.

At any rate, keep at it.  It's worth the effort, I assure you.

**
Rep:
Level 55
RMRK Junior
thnks IXfuru. i followed all the advice. somehow i got a bit problem here. here i trying to add more windows. however the cursor did not updated. i meant when i press key DOwnbutton, the rect did not go down. any ideas how to fix this? i am curious. here are the codes:



Code: [Select]
# KEDAI MAKAN
class Kedai_Makan
  attr_reader :menu, :harga, :info
  def initialize(menu,harga,info)
    @menu = menu
    @harga = harga
    @info = info
  end
end

#sekarang nk buat window selectable untuk menu makanan.
class Window_Menu < Window_Selectable
 
  attr_reader :list_menu
 
  def initialize #ketika ini dia akna bace semua mklumat dlm array.
    super(0,0,200,200)
    self.index = 0
    self.active = true
    @list_menu = [Kedai_Makan.new("Nasi Goreng","RM 3.00","SEDAP!"), Kedai_Makan.new("Mee Goreng","RM4.00","Menjilat Jari"), Kedai_Makan.new("Kuew Teow","RM4.50","Sedap gitu")]
  end
 
  def update #frame update
    super
    @data = @list_menu
    item_max = @data.size
    create_contents
    for arg1 in 0...@data.size
      show_maklumat(arg1)
    end
  end
  def show_maklumat(arg2) #fungsi untuk tunjuk nama menu dlam window_menu
    rect = item_rect(arg2)
    self.contents.clear_rect(rect)
    string = @data[arg2].menu
    rect.width -= 4
    self.contents.draw_text(rect.x,rect.y,rect.width,WLH,string)
  end
end

#skerang but windows untuk show harga
class Window_Harga < Window_Base
  attr_accessor :harga1
  attr_accessor :list_harga
 
  def initialize(list_harga)
    super(205,0,100,100)
    @list_harga = list_harga
    @harga1 = 0
  end
  def refresh
    self.contents.clear
    draw_harga
  end
  def draw_harga
    self.contents.draw_text(0,0,95,WLH,@list_harga[harga1].harga)
  end
end

#sekarang buat windows untuk info mknan
class Window_Info < Window_Base
  attr_accessor :info1
  attr_accessor :list_info
 
  def initialize(list_info)
    super(205,105,100,100)
    @list_info = list_info
    @info1 = 0
  end
  def refresh
    self.contents.clear
    draw_info
  end
  def draw_info
    self.contents.draw_text(0,0,95,WLH,@list_info[info1].info)
  end
end
#sekarang buat scene pula
class Scene_Gerai < Scene_Base
  def start
    @W_menu = Window_Menu.new
    @W_harga = Window_Harga.new(@W_menu.list_menu)
    @W_info = Window_Info.new(@W_menu.list_menu)
  end
  def terminate
    @W_menu.dispose
    @W_harga.dispose
    @W_info.dispose
  end
  def update
    super
    if Input.trigger?(Input::B)
      $scene = Scene_Map.new
    end
    @W_menu.update
    @W_harga.harga1 = @W_menu.index
    @W_harga.refresh
    @W_info.info1 = @W_menu.index
    @W_info.refresh
  end
end
« Last Edit: December 30, 2012, 06:01:57 AM by irfanganu »

**
Rep:
Level 66
RMRK Junior
To me, it looks like it might be something because you're calling create_contents in the update method. That's probably a really bad idea, speed-wise, and might reset the cursor rect. Instead, call create_contents in the initialize method.

**
Rep: +0/-0Level 14
RMRK Junior
canada pharmacy online canada pharmacies online rx pharmacy medication <a href=http://onlinepharmacyif.com/>buy viagra online no rx canada/#pharmacy in canada online</a>

**
Rep: +0/-0Level 14
RMRK Junior
online drugs no prescriptions best online international pharmacies <a href=http://onlinepharmacyif.com/>what is a good online pharmacy/#buy prescription drugs online without prescription</a>

**
Rep: +0/-0Level 14
RMRK Junior
mexican pharmacies online canada drug co <a href=http://onlinepharmacyif.com/>#1 online pharmacy/#buy prescription drugs online without prescription</a>

**
Rep: +0/-0Level 14
RMRK Junior
uk online pharmacies reviews buy prescription drugs online without prescription <a href=http://onlinepharmacyif.com/>viagra rx pharmacy/#mexico pharmacy drugs</a>

**
Rep: +0/-0Level 14
RMRK Junior
on line pharmacies /us no prescription canada drugs <a href=http://onlinepharmacyif.com/>trustpharmacy/#reputable online pharmacies usa</a>

**
Rep: +0/-0Level 14
RMRK Junior
roxicodone online no prescription buying drugs online no prescription <a href=http://onlinepharmacyif.com/>mexican pharmacy/#buy viagra online no rx canada</a>

**
Rep: +0/-0Level 14
RMRK Junior
best online no prescription viagra site mexican online pharmacy reviews <a href=http://onlinepharmacyif.com/>mexican pharmacy online hydrocodone/#trust pharmacy reviews in canada</a>

**
Rep: +0/-0Level 14
RMRK Junior
online usa pharmacy no prescription buy viagra online no rx canada <a href=http://onlinepharmacyif.com/>reputable online pharmacy for generic viagra/#buying drugs online no prescription</a>

**
Rep: +0/-0Level 14
RMRK Junior
cheap online pharmacy buy medication online without script <a href=http://onlinepharmacyif.com/>buy tramadol online no prescription/#buy prescription online pharmacy</a>

**
Rep: +0/-0Level 14
RMRK Junior
canada pharmacy no prescription antibiotics best online pharmacies without prescription <a href=http://onlinepharmacyif.com/>trusted canada pharmacy/#list of canada online pharmacies</a>

**
Rep: +0/-0Level 14
RMRK Junior
canada pharmacy online canada pharmacies canadian pharmacy online cialis <a href=http://onlinepharmacyif.com/>viagra online canada pharmacy/#pharmacy unscripted</a>

**
Rep: +0/-0Level 14
RMRK Junior
mexican online pharmacy reviews no prescription usa pharmacy <a href=http://onlinepharmacyif.com/>best india pharmacies online/#buying tramadol without prescription</a>

**
Rep: +0/-0Level 14
RMRK Junior
online pharmacy canada generic online pharmacy <a href=http://onlinepharmacyif.com/>mexican pharmacies online/#canadian pharmacy online drugstore</a>

**
Rep: +0/-0Level 14
RMRK Junior
online pharmacy #1 online pharmacy usa <a href=http://onlinepharmacyif.com/>on line canadain pharmacy/#no prescription foreign pharmacies online</a>

**
Rep: +0/-0Level 14
RMRK Junior
legitimate online pharmacies india best online pharmacy for viagra <a href=http://onlinepharmacyif.com/>online prescription drugs vipps/#on line pharmacy uk</a>

**
Rep: +0/-0Level 14
RMRK Junior
canada pharmacy online viagra trust pharmacy ebay <a href=http://onlinepharmacyif.com/>pharmacy in canada online/#vicodin online pharmacy</a>