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.

Variable for storing previous scene?

Just wondering if there's any way a scene can see what scene it was called from so it can go back to the scene it was called from, from any number of possible scenes it could have been called from.
 
If this is in a custom scene, then I recommend giving the scene an Initialize method, and giving it an argument for the transferring scene. I recommend that the argument be a string, and that you use an if statement to go back to the other scene. Alternatively, you could store the scene itself in the argument, to be restored when you're done.
 
The argument he refers to is called a 'callback' parameter, or variable. For example, I've re-written the initialize method for Lambchop's Super Simple Journal script to accept an optional argument

class Scene_Journal
  def initialize(callback = 0)
    @callback = callback


In the method where the escape/X (Input::B) key is pressed, I check the callback parameter & call the appropriate scene

     if @callback == 1
        $scene = Scene_Menu.new(4)
      else
        $scene = Scene_Map.new
      end


This is to accommodate calling the scene from either the map, using the Q (Input::L) key

     $scene = Scene_Journal.new(1)
 

or calling it from the modified menu

     $scene = Scene_Journal.new
 
 

Zeriab

Sponsor

You can also store the scene itself.
class Scene_Journal
  def initialize(callback = $scene)
    @callback = callback


In the method where the escape/X (Input::B) key is pressed, I check the callback parameter & call the appropriate scene
$scene = @callback


If you for some reason want or have to create a new scene object then you can do it like this:
class Scene_Journal
def initialize(callback = $scene, *args)
@callback = callback.class
@arguments = args


In the method where the escape/X (Input::B) key is pressed, I check the callback parameter & call the appropriate scene
$scene = @callback.new(*@arguments)


*hugs*
-Zeriab
 

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