The Script Builders' Tutorials:
----Lesson 6: Scenes----
II. The Main Method
III. The Update Process
IV. Command Windows in Scenes
VII. HomeworkI. Introduction
Hey R3! It’s definitely been a while since the last tutorial. This tutorial is about scenes, a nice wrap-up to the windows lessons. Scenes are like the house in which the windows are the residents of. For example, Scene_Menu is a house in which Window_Gold, Window_PlayTime, Window_Steps, and Window_MenuStatus are residents of. In this tutorial, you’ll learn how set the residents (windows) of your house (scene), how to tell them what do, and how to use command windows inside of scenes.II. The Main Method
Open up your script editor in a new rmxp project and go to Scene_Menu. You’ll notice that the second method is main, which is a method in almost every scene. In this part of the tutorial, I’m going to explain the function of main in scenes.
In the main method, you declare all the objects that you'll be putting together (I say objects because scenes don’t always have only windows, they might have a spriteset like Scene_Map, or a picture like Scene_Title). An example of this is on lines 41 to 56 of Scene_Menu. It shows the following:
# Make play time window
@playtime_window = Window_PlayTime.new
@playtime_window.x = 0
@playtime_window.y = 224
# Make steps window
@steps_window = Window_Steps.new
@steps_window.x = 0
@steps_window.y = 320
# Make gold window
@gold_window = Window_Gold.new
@gold_window.x = 0
@gold_window.y = 416
# Make status window
@status_window = Window_MenuStatus.new
@status_window.x = 160
@status_window.y = 0
The above code allows the Menu Scene to show the playtime, steps, gold, and menustatus windows. It’s what I like to call the Residents Section. You also notice in the above code that you can specify new window coordinates so that you can change them all in one place. You simply have to add ‘.x’ or ‘.y’ to the window so that you can have access to that method and then put an equals sign and then the number you want.
(P.S. Do not pay attention to the code in scene_menu from lines 19 to 40. We’ll discuss that in section 4 of this tutorial.)
The next part of the main method is what I like to call the Transition Section. It pretty much looks like this for every scene:
# Execute transition
# Main loop
# Update game screen
# Update input information
# Frame update
# Abort loop if screen is changed
if $scene != self
# Prepare for transition
Here, what happens is that the scene keeps looping itself (That means the scene keeps doing the same thing) while it's itself. When you go to another scene, like Scene_Item, the loop breaks, and the graphics freeze so that they can be transitioned to the new scene. In the loop, graphics and input are updated and the update method is called (Which will be discussed in the next section). After the Transition Section we have the Disposal Section where you dispose all the objects that you declared. An example of this in action is on lines 75 to 79 of Scene_Menu:
Also, notice the initialize method above the main method. The initialize method is called when the respective scene is called. In Scene_Menu, the initialize method is used to put the command window’s index at the right spot. Look at line 33 of Scene_Save. After exiting out of the Scene_Save, the initialize method helps bring the command window index in Scene_Menu back to where it was when it pressed “Save”.III. The Update Process
Go back to Scene_Menu in your script editor if you’re not already there and notice that after the main method, we have the update method. Here is where everything gets done. Look at lines 85 to 90 of Scene_Menu:
# Update windows
You add ‘.update’ to each object in your scene so that they each get affected by the update method. After that, you start the process of going into specific updating. Specific updating can be found from lines 91 to 100 of Scene_Menu:
# If command window is active: call update_command
# If status window is active: call update_status
What happens is that in specific updating, you make it so that if a certain condition is met, the update method jumps to another update method which specifically updates the object that has met that certain condition. For example, look at the second part of the code above (starting at line 96), it shows that if the status window is active, then the update method will jump to the update_status method. Now, you must be wondering what the active method. The active method is used only for selectable windows. It checks to see whether the window is able to respond to user input or not. So basically, let’s say you opened up your menu while play testing your game. If the command window in the menu wasn’t active, you wouldn’t be able to do anything with it. If it was, you’d be able to select the different options.
The other type of condition you could use would be something like the following code:
# If status window is active: call update_status
This basically means if the status window is visible, or can be seen, the update_status method will be called.
Now let’s move on to the method this code above branches off to, which is the update_status method. It looks like this:
# If B button was pressed
# Play cancel SE
# Make command window active
@command_window.active = true
@status_window.active = false
@status_window.index = -1
# If C button was pressed
# Branch by command window cursor position
when 1 # skill
# If this actor's action limit is 2 or more
if $game_party.actors[@status_window.index].restriction >= 2
# Play buzzer SE
# Play decision SE
# Switch to skill screen
$scene = Scene_Skill.new(@status_window.index)
when 2 # equipment
# Play decision SE
# Switch to equipment screen
$scene = Scene_Equip.new(@status_window.index)
when 3 # status
# Play decision SE
# Switch to status screen
$scene = Scene_Status.new(@status_window.index)
What this piece of code first does is check to see if the player has pressed the cancel button. If so, the cancel SE is played and status window’s active state is set to false, and the command window’s active state is set to true which makes the update process jump to the update_command method.
The next part of the code checks to see if the player presses the confirm button. If so, the code goes into a case statement (a description of case statements can be found here: http://www.rpgrevolution.com/tutorial/rgss...l-flow_27.html)
. What it does is make it so that if the player chooses either the skill, equip, or status options, the status window becomes active and the player chooses which actor they’d like to see the skill, equipment, or status. When the player chooses, the scene is changed to whichever option the player chose from in the menu.
Basically, when in the update process and you branch off to other methods, you simple have to know how to code that part. After practice and looking over the default scripts, you’ll find it easy to come up with ways to code updating of that window or object. IV. Command Windows
In tutorial 4 of the Script Builders, we made it so that we didn’t have a scene but still produced a command window. Command windows are usually found in scenes, but since we only we’re trying to teach you guys about command windows last time, we didn’t put it in a scene.
Command windows are like ports to other houses or scenes when used as part of a scene. The command window in the menu allows you to go to several other scenes like the Item scene, the Status scene, etc.
To make command windows is pretty simple. Just like last time, you would state the commands used in the scene and then make the line that puts it all together. An example of this is on lines 20 to 26 of Scene_Menu:
s1 = $data_system.words.item
s2 = $data_system.words.skill
s3 = $data_system.words.equip
s4 = "Status"
s5 = "Save"
s6 = "End Game"
@command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
That’s what we already know. The new part, however, is the update section. Look at Scene_Menu from lines 92 to 95. If the command window is active, which by default it is, it branches off to the update_command method. Basically, the update_command method is like the update_status method. If the player presses the cancel button, the menu scene changes to the map scene and if the player presses confirm, the method makes a case statement to check what index the command window was on so that it can direct you to the correct scene.V. Conclusion
Well that’s it for this tutorial. Hopefully I explained everything pretty well, if not, please just post your concern. So basically, this is what we’ve learned:
- Scenes are kinda like houses in which several objects live (windows, spritesets, pictures, etc).
- The update process is a complex part of scenes in which you branch off into different methods in order to update something if a certain condition is met.
- Command windows in scenes are like ports. They allow you to move from one scene (one house) to another via user input.
Try making your own custom scene that contains maybe default windows or even windows you’ve made. Try to also add other objects, if you can, besides windows like pictures, spritesets, etc. Good luck!