[ERROR] Undefined method 'bitmap' for 0:Fixnum

● ARCHIVED · READ-ONLY
Started by Ultim 13 posts View original ↗
  1. Hello Everybody !

    I've been testing my script,when this error popped up.Please help ! Here's the code :

    Spoiler
    def start  super()  @background_sprite        =  Sprite.new()  @background_sprite        =  Cache.picture("background")   @background_sprite        =  0  @background_sprite        =  0  @background_sprite.zoom_x =  544.0 / @background_sprite.bitmap.width  @background_sprite.zoom_y =  414.0 /  @background_sprite.bitmap.heightend
    Thanks in Advance !
  2. Probably 

    @background_sprite = 0 @background_sprite = 0What are you trying to do with those lines anyway?

    Did you mean:

    Code:
      @background_sprite.x        =  0  @background_sprite.y        =  0
  3. Creating a Sprite background.I'll try your suggestion.And thank you for your time.
  4. Yeah, you shouldn't need to set the picture to zero, that's most likely the cause of the error since a bitmap/picture shouldn't be set to a number. 

    But the x and y values can be set to zero, which is what I thought you were trying to do.
  5. I tried your suggestion,but it threw me another error :

    "Script U1G Simple RPS System line 36 : NoMethodError occured

    undefined method "x=" for #<Bitmap0xb7b0dbc>"

    Here's the complete code if you want to check it :

    Spoiler
    Code:
    #-------------------------------------------------------------------------------#       U1G Engine - Simple Rock-Paper-Scissors System V.1.2#                                          By : Ultim1337Gamer## This easy-to-use script adds a Rock-Paper-Scissors scene in your game.#-------------------------------------------------------------------------------#================================HOW TO USE====================================## -Plug & Play.Edit if needed.                                                 ## -Call the scene using the script call SceneManager.call(Scene_RPS)           ## -NOTE : DON'T edit outside editable zones UNLESS you KNOW what you're doing. ## -NOTE :Don't edit Non-Commented code UNLESS you KNOW what you're doing.      ##==============================================================================##===============================CHANGELOG======================================## V.1.1 : Beta                                                                 ## V.1.2 : Cleaned & made the code easily readable,Added background,aliases,and ## other stuff                                                                  #                                 #==============================================================================##                            CREDITS & TERMS OF USE#-Free for both Commercial and Non-Commercial Projects as long as I'm credited# "Ultim1337Gamer"#----------------------------------CREDITS--------------------------------------#-My Brain and Hands   : For thinking and typing this script.#-DiamondandPlatinium3 : For his awesome RGSS3 Tutorials#===============================================================================                            # SCRIPT STARTING #class Scene_RPS < Scene_Base                            #===============================================================================# 1st EDITABLE ZONE STARTING :#===============================================================================# Creates Backgrounddef start  super()  @background_sprite         =  Sprite.new()  @background_sprite         =  Cache.picture("background") # The image that'll serve as a background  @background_sprite.x        =  0  @background_sprite.y        =  0  @background_sprite.zoom_x  =  544.0 / @background_sprite.bitmap.width  @background_sprite.zoom_y  =  414.0 /  @background_sprite.bitmap.heightend#------------------------------------------------------------------------------## Creates Titledef create_title  @title = Window.help.new(1)  BattleManager.save_bgm_and_bgs # Saves the BGM and BGS in the last scene.  RPG::BGM.new("Battle1",100, 100).play    # The BGM that'll play in the scene.  @title.set_text("Rock-Paper-Scissors!")  # Text to display as a title.end#------------------------------------------------------------------------------#def create_commands  @window_selection = Window_RPS.new(0, 48)  @window_selection.set_handler(:rock, method(:rock))  @window_selection.set_handler(:paper, method(:paper))  @window_selection.set_handler(:scissors, method(:scissors))end#===============================================================================# End of 1st Editable Zone.Editing past this point will cause brain explosion.#===============================================================================def generate_choice  weapon_list [:rock, :paper, :scissors]  @computer_choice = weapon_list.sampleend# Creates Window Messagedef create_window_message  @message = Window_Base.new(132, 168, 280, 80)  @message.hideend# Shows Messagedef display_message(text, number)  @message.draw_text(0, 0, 280, 38, text)  message = "Win!"  # Message to diplay in case of winning (EDITABLE)  if number == 0  message = "Tie!"  # Message to display in case of a tie (EDITABLE)  elsif number == 1  message = "Loss!" # Message to display in case of a loss (EDITABLE)end  @message.draw_text(0, 20, 280, 38, message)  @message.showend#-------------------------------------------------------------------------------# Choice : Rockdef rock  if @computer_choice == :rock  display_message("You:Rock COM:Rock", 0)    # Shows your and COM's Results(EDITABLE)  SceneManager.call(Scene_RPS)  elsif @computer_choice == :paper  display_message("You:Rock COM:Paper", 1)   # Shows your and COM's Results(EDITABLE)  SceneManager.call(Scene_RPS)  else  display_message("You:Rock COM:Scissors", 2)# Shows your and COM's Results(EDITABLE)  SceneManager.call(Scene_RPS)endend# Choice : Paperdef paper  if @computer_choice == :paper  display_message("You:Paper COM:Paper", 0)   # Shows your and COM's Results(EDITABLE)  SceneManager.call(Scene_RPS)  elsif @computer_choice == :scissors  display_message("You:Paper COM:Scissors", 1)# Shows your and COM's Results(EDITABLE)  SceneManager.call(Scene_RPS)  else  display_message("You:Paper COM:Rock", 2)    # Shows your and COM's Results(EDITABLE)  SceneManager.call(Scene_RPS)endend# Choice : Scissorsdef scissors  if @computer_choice == :scissors  display_message("You:Scissors COM:Scissors", 0) # Shows your and COM's Results(EDITABLE)  SceneManager.call(Scene_RPS)  elsif @computer_choice == :rock  display_message("You:Scissors COM:Rock", 1) # Shows your and COM's Results(EDITABLE)  SceneManager.call(Scene_RPS)  else  display_message("You:Scissors COM:Paper", 2) # Shows your and COM's Results(EDITABLE)  SceneManager.call(Scene_RPS)endend# Quitting the Scene :   def terminate  super()  return_scene()  @background_sprite.bitmap.dispose()  @background_sprite.dispose()  BattleManager.replay_bgm_and_bgsend# "Weapon" Selection Windowclass Window_RPS < Window_Command# Choice Window Creation (Don't Edit yellow text!!"def make_command_list  add_command("Rock", :rock)         # Weapon name in Choice window.(EDITABLE)  add_command("Paper", :paper)       # Weapon name in Choice window.(EDITABLE)  add_command("Scissors", :scissors) # Weapon name in Choice window.(EDITABLE)endendend
  6. change

    @background_sprite = Cache.picture("background") # The image that'll serve as a backgrounto

    @background_sprite.bitmap = Cache.picture("background") # The image that'll serve as a backgrounBecause you just put a picture into your sprite variable, changing the variable type.
  7. Thank you Napoleon.I'll try that.

    EDIT : IT WORKED !!! Just a issue,the def create_title method dosen't work...The scene dosen't work...
  8. I'm not too good at scripting and you code a whole lot different than I do, so I'm not sure :p

    Looks pretty complicated for one of your firsts though!

    (I meant that in a good way)
  9. when you start you class, you usually set up a initial method where you set what the class does when it starts.. usually you set some variables and things that should start up right away.. like in windows you'd draw the contents (usually by calling a refresh method).

    Scenes work the same way, but instead of a initalize method they use "start". So for you scene, all you've told it to do is to create a sprite and display an image. You'll need to add methods to it. Like:

    Code:
    def start  super()  @background_sprite         =  Sprite.new()  @background_sprite.bitmap  =  Cache.picture("background") # The image that'll serve as a background  @background_sprite.x       =  0  @background_sprite.y       =  0  @background_sprite.zoom_x  =  544.0 / @background_sprite.bitmap.width  @background_sprite.zoom_y  =  414.0 /  @background_sprite.bitmap.height  create_title  create_commands  create_window_messageend
  10. THANK YOU VENKA !!!!! Worked without issue.
  11. Perhaps you should look around at some Ruby tutorials and how to get / set an object's properties (aka variables). For instance, you were calling this code:

    def start super() @background_sprite = Sprite.new() @background_sprite = Cache.picture("background") @background_sprite = 0 @background_sprite = 0 @background_sprite.zoom_x = 544.0 / @background_sprite.bitmap.width @background_sprite.zoom_y = 414.0 / @background_sprite.bitmap.heightendDo you fully understand the code you just wrote, or did you write it by looking / copying from another source? Here are quite a few problems with your code:1) @background_sprite is being set to a new Sprite object, but then is set to a Bitmap object on the next line. The next two lines after that both set @background_sprite to 0. From the context, I'm assuming you were trying to set the sprite's bitmap, x, and y variables, so you need to do as Venka suggessted.

    2) The line "@title = Window.help.new(1)" will throw an error; perhaps you meant: "@title = Window_Help.new(1)" ?

    3) I would also recommend that you move the code that creates the background into it's own method, and call that method from the start() method.

    4) All your if; elsif blocks of code are missing the end off of them, like so:

    if some_condition do_stuffelsif this_other_condition do_other_stuffend # this end is required for your script to not errorI think this is why you had to add those ends on at the bottom of your script, right?5) In your rock(), paper(), and scissors() methods, don't use SceneManager.call(Scene_RPS); this is adding tons of instances of Scene_RPS to the SceneManager array of scenes, and when you call return_scene(), it'll just be Scene_RPS again, not Scene_Map.

    6) Speaking of return_scene(), why is it in terminate()? I'm not sure you understand how the RPG Maker scene system works, but I would recommend that you remove it from terminate(). and add it to @window_selection, like so:

    Code:
    @window_selection.set_handler(:cancel, method(:return_scene))
    I would also merging all of the rock(), paper(), and scissors() commands into one, like so:
    Code:
    @window_selection.set_handler(:ok, method(:choose_rps))def choose_rps  case @window_selection.current_symbol  when :rock    do_rock_stuff  when :paper    do_paper_stuff  when :scissors    do_scissors_stuff  endend
    Does all of that make sense? Ask away if it doesn't :)
  12. Thanks for suggestion.And I fully understand the code I write.
  13. This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.