Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: jayje on August 10, 2010, 10:50:32 pm

Title: Got a problem here,
Post by: jayje on August 10, 2010, 10:50:32 pm
a friend of mine made a script for that gives me a NoMethodError on line # 85
"undefined method `nil?' for #<Sprite:0x3f49298>"

Spoiler: ShowHide
#---------------------------------------------------------
# Ignore this part. It simply tells RMXP to
# stop looping the menu index from bottom to top.
#---------------------------------------------------------
class Window_Command < Window_Selectable

 def set_commands(list)
   if (!list.nil?)
     @commands = list
   end
   refresh
 end
 
 def update
   old_index = (self.index)
   super
   # stop looping
   if (old_index > (self.index) +1) or (old_index < (self.index) -1)
     self.index = old_index
   end
 end
 
end
#---------------------------------------------------------------------#
#     Scene_Monstruct_Menu                                            #
# Changes: menu scrolls to show all the options.                      #
#          new class: Window_Monstruct                                #
#                                                                     #
#  Notes:                                                             #
#  - The tiny arrows are made by me.                                  #
#     copy them into your game's Pictre folder.                       #
#  - you need to edit the methods make_list & get_picture             #
#                                                                     #
#---------------------------------------------------------------------#
class Scene_Monstruct_Menu
 
 def main
   # this line shows the map behind the menu
   # if you erase it, the screen will be black around it.
   @spriteset = Spriteset_Map.new  
   # list of menu commands (monstruct names)
   # scroll down to see what 'make_list' does.
   @commands = make_list
   # only show 6 names at a time:
   @commands_max = [6,@commands.size].min
   # use the first 6 names as a menu.
   @list = Array.new
   for i in 0...@commands_max
     @list.push(@commands[i])
   end
   # these two variables are used to get the 'real' index in the list.
   # normally, it's simply menu.index but since we're scroling
   # we must calculate it.
   @list_start = 0
   @start_from = 0
   @end_in = @commands_max
   # command_window is our menu
   @command_window = Window_Command.new(160, @list)
   @command_window.index = 0
   @command_window.back_opacity = 200
   # in rmxp you must draw a picture inside a window
   # I made a new window class for it.
   @pic_window = Window_Monstruct.new
   @pic_window.opacity = 0
   # Execute transition
   Graphics.transition
   # Main loop
   loop do
     # Update game screen
     Graphics.update
     # Update input information
     Input.update
     # Frame update
     update
     # Abort loop if screen is changed
     if $scene != self
       break
     end
   end
   # Prepare for transition
   Graphics.freeze
   # Dispose of windows
   @command_window.dispose
   @spriteset.dispose if !@spriteset.nil?      
   if (!@down.ni?) : @down.dispose end <-----------(like 85)
   if (!@up.nil?)  : @up.dispose end
 end
 
 def update
   # Update windows
   @command_window.update
   # If command window is active: call update_command
   if @command_window.active
     update_command
     return
   end
 end
 
 #-------------------------------------------------------
 # edit below to create the list the way you want it.
 #-------------------------------------------------------
 def make_list
   list = []
   switches = []
   # push all names into the array
   for i in  1401..1553
     switches.push(i)
   end

   for id in switches
     if $game_switches[id]
       k = id-1400
       name = $data_enemies[k].name
       list.push(name)
     end
   end
   #while list.size < 6
     #list.push 'Empty'
   #end
   
   return list
 end
 
 def update_command
   # If B button was pressed
   if Input.trigger?(Input::B)
     # delete the arrows
     if (!@down.nil?): @down.dispose end
     if (!@up.nil?): @up.dispose end
     # Play cancel SE
     $game_system.se_play($data_system.cancel_se)
     # Switch to map screen
     $scene = Scene_Map.new
     return
   end
   # If C button was pressed
   if Input.trigger?(Input::C)
     # delete the arrows
     if (@down): @down.dispose end
     if (@up): @up.dispose end
     # Play decision SE
     $game_system.se_play($data_system.decision_se)
     # get menu index
     @list_index = @command_window.index + @start_from
     # get the name of the monstruct we're pointing at
     monstruct = @commands[@list_index]
     # use the new class to show the picture
     @pic_window.draw(monstruct)
     return
   end
   # show an arrow up/ down if there are more options
   update_scroll_arrow
   # making the menu scroll up/down
   index = @command_window.index
   if (Input.trigger?(Input::DOWN))&&(index ==@commands_max-1)
     scroll_down
     return
   end
   if (Input.trigger?(Input::UP))&&(index ==0)
     scroll_up
   end
 end
 
 def scroll_down
   index_fix = 0
   @start_from = @list_start + @commands_max
   @end_in = @start_from + @commands_max
   if (@end_in > @commands.size)
     index_fix = @end_in - @commands.size
     @end_in = @commands.size
     @start_from = @end_in - @commands_max
   end
   @list = Array.new
   for i in (@start_from)...(@end_in)
     @list.push(@commands[i])
   end
   @list_start += @commands_max -1
   @list_start -= index_fix
   @command_window.dispose
   @command_window = Window_Command.new(160, @list)
   @command_window.back_opacity = 200               # new
   @command_window.active = true
   @command_window.index = @commands_max-1
 end
 
 def scroll_up
   index_fix = 0
   @start_from = @list_start - @commands_max-1
   @end_in = @start_from + @commands_max
   if (@start_from<0)
     index_fix = @start_from
     @start_from = 0
     @end_in = @commands_max
   end
   if (@end_in > @commands.size)
     index_fix = @end_in - @commands.size
     @end_in = @commands.size
     @start_from = @end_in - @commands_max
   end
   @list = Array.new
   for i in @start_from...@end_in
     @list.push(@commands[i])
   end
   @list_start = @list_start - @commands_max +1
   @list_start -= index_fix
   @command_window.dispose
   @command_window = Window_Command.new(160, @list)
   @command_window.back_opacity = 200               # new
   @command_window.active = true
   @command_window.index = 0
 end
 
 def show_down_arrow
   @down = Sprite.new
   @down.bitmap = RPG::Cache.picture("arrow_down.png")
   @down.z = 101
   @down.x = 60
   @down.y = 6*32+16
 end

 def show_up_arrow
   @up = Sprite.new
   @up.bitmap = RPG::Cache.picture("arrow_up.png")
   @up.z = 101
   @up.x = 60
   @up.y = 10
 end

 def update_scroll_arrow
   # show an arrow up/ down if there are more options
   index = @command_window.index +@start_from
   commands = @commands.size
   item_max = index + @commands_max
   if (commands >item_max)
    show_down_arrow
   else
     if (@down): @down.dispose end
   end
   item_min= index-@commands_max
   if  (index>@commands_max-1)      
     show_up_arrow
   else
     if (@up): @up.dispose end
   end
 end
end

#-------------------------------------------------------
#  This class shows a 400x400 window
#      with a monster picture in it.
#-------------------------------------------------------
class Window_Monstruct < Window_Base
 
 def initialize
   super(160, 0, 480, 480)
   self.contents = Bitmap.new(width - 32, height - 32)
 end
 
 #---------------------------------------------
 # edit below to set which picture is shown
 #---------------------------------------------
 def get_picture(name)
   hue = 0
   # name is the name of the monstruct
   # use it to decide which picture to use :
   # case (name)
   # when 'badger'
   #   filename = 'badger_battler.png'
   # when 'unicorn'
   #   filename = 'unicorn2.png'
   # end
   filename = name + " Page.png"
   return RPG::Cache.load_bitmap("Graphics/Manual/",filename, hue)
 end
 
 def draw(name)
   self.contents.clear
   bitmap = get_picture(name)
   cw = bitmap.width
   ch = bitmap.height
   x =  40
   y =  40
   src_rect = Rect.new(0, 0, cw, ch)
   self.contents.blt(x - 46 / 2, y - 70, bitmap, src_rect)
 end
 
end


any help would be great
Title: Re: Got a problem here,
Post by: Sacred Nym on August 10, 2010, 11:23:14 pm
You have (!@down.ni?) when it should be (!@down.nil?)
Title: Re: Got a problem here,
Post by: jayje on August 11, 2010, 12:01:00 am
wow. well that's embarrassing. thanks.
Title: Re: Got a problem here,
Post by: Sacred Nym on August 11, 2010, 12:18:36 am
It happens to all of us, Don't worry about it.
Title: Re: Got a problem here,
Post by: Blizzard on August 11, 2010, 02:32:44 am
That's why I don't use .nil? but compare to nil instead. -_-