Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Resolved]Calling methods of other classes

How do I call a certain method of a Class that's not the current class, nor is it the parent of it?

For example, i want to start a new game instead of getting the buzzer sound at Scene_Load (i know how to do that)
but without copying the code of Scene_Title.command_new_game in Scene_Load
Instead i just want to make a call to Scene_Title.command_new_game so that that part is processed. (improving enourmous on compability ;))
 
Not really sure here, but wouldn't you define a new object, say, NewGame, for instance (you might probably want a better name) and do this:

Code:
NewGame = Scene_Title.new
NewGame.command_new_game

I think that would call the command_new_game method in Scene_Title, but someone please correct me, because I'm kind of new to this.

Edit: Chaosg1, you beat me to it! Well... I'll leave my bit here anyway, even if yours does look better.
 
well... thanks both of you... i needed to combine your solutions to make it actually work XD
Code:
$scene_title = Scene_Title.new
$scene_title.command_new_game
Code:
#============================================================================
# ** Scene_Load addition
#----------------------------------------------------------------------------
#  This class performs load screen processing.
#============================================================================

class Scene_Load < Scene_File
  alias alx_on_decision on_decision
  #--------------------------------------------------------------------------
  # * Decision Processing
  #--------------------------------------------------------------------------
  def on_decision(filename)
    # If file doesn't exist
    unless FileTest.exist?(filename)
      $scene_title = Scene_Title.new
      $scene_title.command_new_game
      return
    end
    alx_on_decision(filename)
  end
end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top