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.
One thing I'm having trouble with is figuring out an EASY way to determine the previous scene. Maybe it's obvious, and I'm just clueless, but are there any suggestions? (-_- I think I used to know how to do this too...)
In the initialize of the new scene you can add a parameter so you know what the last scene is.
Code:
class Scene_Test
def initialize(last_scene = 'Scene_Title')
@last_scene = last_scene
end
def main
Graphics.transition
loop do
Graphics.update
Input.update
update
break if $scene != self
end
Graphics.freeze
end
def update
if Input.trigger?(Input::B)
$scene = eval(@last_scene).new
end
end
end
The last scene would be a string. So when you say create the instance of this class.
Code:
$scene = Scene_Text.new('Scene_Whatever')
But for some reason I think SephirothSpawn just answered a question about this recently so his answer probably makes a bit more sense than mine. Found it:
The way his works is because at the time of the new scene is constructed the previous scene has not yet been changed. I like his answer better no need to even know what the current scene is with his answer.
Code:
class Scene_Test
def initialize
@last_scene = $scene.class
end
def main
Graphics.transition
loop do
Graphics.update
Input.update
update
break if $scene != self
end
Graphics.freeze
end
def update
$scene = @last_scene.new if Input.trigger?(Input::B)
end
end
Hmm I'm curious as to why would you want to change to the same scene? In Scene_Map the only reason I can think of would be moving the player or reseting events? The reason however it does not change is because it doesn't break the loop in main.
Code:
break if $scene != self
Because it technically is the same scene. What you'll need for this occassion is the addition of a boolean that if true will break.
Code:
class Scene_Test
def initialize
@break = false
@last_scene = $scene.class
end
def main
Graphics.transition
loop do
Graphics.update
Input.update
update
break if $scene != self || @break
end
Graphics.freeze
end
def update
if Input.trigger?(Input::B)
$scene = @last_scene.new
@break = true
end
end
end