Submit Your Article Guild Wars 2 Forum RPG Maker VX.com
 
RPG Maker
 

 Username:
 Password:
   Not a member? Register!



Home > RGSS Script Reference > |Iterator|

|Iterator|


Description: Iterators allow you to call a block of code from within a method by using the "yield" keyword (also described in the syntax documentation). Once the method ends, control is transferred back to the method that called the iterator block's code, right after the "yield" statement. You'll notice that the code sample for iterators is the same as for "yield". This is to highlight their relationship to each other. You can declare an iterator block only on the line where a method definition begins, immediately following the method's last argument. If the method encounters a "yield" statement, then the code in the block will be executed with the yield's parameters. An iterator is always enclosed in pipe characters (|) as shown in the code example.

There are also built-in methods that use iterators implcitly, such as the array method "each", which, when invoked, simply yields each element in the array in succession.

Code Sample:
def iterate_battler(parameter1, parameter2)
    if parameter1 == 0
      iterate_enemy(parameter2) do |enemy|
        yield enemy
      end
    else
      if parameter2 == -1
        for actor in $game_party.actors
          yield actor
        end
      else
        actor = $game_party.actors[parameter2]
        yield actor if actor != nil
      end
    end
  end
end


def command_337
    iterate_battler(@parameters[0], @parameters[1]) do |battler|
      if battler.exist?
        battler.animation_id = @parameters[2]
      end
    end
    return true
  end

Syntax
@
@@
$
alias
[array index]
attr_accessor
attr_reader
attr_writer
class
def
do
ensure
for
if
[iterator]
key => value
new
next
nil
redo
require
return
rescue
self
super
undef
unless
until
while
yield

Classes
Arrow_Actor
Arrow_Base
Arrow_Enemy
Game_Actor
Game_Actors
Game_BattleAct
Game_Battler
Game_Character
Game_Common
Game_Enemy
Game_Event
Game_Map
Game_Party
Game_Picture
Game_Player
Game_Screen
Game_SlfSwitch
Game_Switches
Game_System
Game_Troop
Game_Variables
Interpreter
Scene_Debug
Scene_End
Scene_Equip
Scene_File
Scene_Gameover
Scene_Item
Scene_Load
Scene_Map
Scene_Menu
Scene_Name
Scene_Save
Scene_Shop
Scene_Skill
Scene_Status
Scene_Title
Sprite_Battler
Sprite_Character
Sprite_Picture
Sprite_Timer
Spriteset_Battle
Spriteset_Map
Window_Base
Window_Battleresult
Window_Battlestatus
Window_Command
Window_DebugLeft
Window_DebugRight
Window_EquipItem
Window_EquipLeft
Window_EquipRight
Window_Gold
Window_Help
Window_InputNumb
Window_Item
Window_MenuStatus
Window_Message
Window_NameEdit
Window_NameInput
Window_PartyCom
Window_PlayTime
Window_SaveFile
Window_Selectable
Window_ShopBuy
Window_ShopCom
Window_ShopNum
Window_ShopSell
Window_ShopStatus
Window_Skill
Window_SkillStatus
Window_Status
Window_Steps
Window_Target

Other
Class Hierarchy
Global Variables


RPG RPG Revolution
RPG RPG Revolution is your #1 stop for game development and console RPG games, as well as those created by people like you. Link to us to support us, so we may grow to be better website community for you.

RPG RPG Revolution is an Privacy Policy and Legal