Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> [Scripting]Scenes, A tutorial from the Script Builders
The Law G14
post Feb 6 2010, 09:38 AM
Post #1


Scripter FTW
Group Icon

Group: Local Mod
Posts: 1,346
Type: Scripter
RM Skill: Skilled
Rev Points: 5




The Script Builders' Tutorials:
----Lesson 6: Scenes----


I. Introduction
II. The Main Method
III. The Update Process
IV. Command Windows in Scenes
VI. Conclusion
VII. Homework


I. 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:

CODE
# 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:

CODE
# Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze


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:

CODE
@command_window.dispose
    @playtime_window.dispose
    @steps_window.dispose
    @gold_window.dispose
    @status_window.dispose


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:

CODE
# Update windows
    @command_window.update
    @playtime_window.update
    @steps_window.update
    @gold_window.update
    @status_window.update


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:

CODE
# If command window is active: call update_command
    if @command_window.active
      update_command
      return
    end
    # If status window is active: call update_status
    if @status_window.active
      update_status
      return
    end


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:

CODE
    # If status window is active: call update_status
    if @status_window.visible
      update_status
      return
    end


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:

CODE
def update_status
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Make command window active
      @command_window.active = true
      @status_window.active = false
      @status_window.index = -1
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Branch by command window cursor position
      case @command_window.index
      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
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to skill screen
        $scene = Scene_Skill.new(@status_window.index)
      when 2  # equipment
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to equipment screen
        $scene = Scene_Equip.new(@status_window.index)
      when 3  # status
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to status screen
        $scene = Scene_Status.new(@status_window.index)
      end
      return
    end
  end


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:

CODE
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.



VI. Homework

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!


__________________________

To put in sig, copy this link:
CODE
[url="http://www.rpgrevolution.com/forums/index.php?showtopic=51540"][img]http://img40.imageshack.us/img40/6504/conceptthelawbanner.png[/img][/url]


Sig Stuff


"When you first come, no one knows you. When help them out, they all know you. When you leave, they all love you. When you come back, they've already forgotten you." -- copy into your sig if you think this quote speaks true!

If you are one of the very few teenagers that know what real rap is and don't blindly listen to the hate statements (rap is crap), then put this in your sig. I say this in the name of Common, Mos Def, Lupe Fiasco, 2Pac, Nas, Talib Kweli, Eminem, and many others. -Exiled One

My Project Thread: Gai's Hunters


Go to the top of the page
 
+Quote Post
   
The Law G14
post Feb 9 2010, 02:38 PM
Post #2


Scripter FTW
Group Icon

Group: Local Mod
Posts: 1,346
Type: Scripter
RM Skill: Skilled
Rev Points: 5




Has anyone looked over this? Any problems people have had understanding this tutorial? Some comments or homework would be nice lol tongue.gif


__________________________

To put in sig, copy this link:
CODE
[url="http://www.rpgrevolution.com/forums/index.php?showtopic=51540"][img]http://img40.imageshack.us/img40/6504/conceptthelawbanner.png[/img][/url]


Sig Stuff


"When you first come, no one knows you. When help them out, they all know you. When you leave, they all love you. When you come back, they've already forgotten you." -- copy into your sig if you think this quote speaks true!

If you are one of the very few teenagers that know what real rap is and don't blindly listen to the hate statements (rap is crap), then put this in your sig. I say this in the name of Common, Mos Def, Lupe Fiasco, 2Pac, Nas, Talib Kweli, Eminem, and many others. -Exiled One

My Project Thread: Gai's Hunters


Go to the top of the page
 
+Quote Post
   
SowS
post Feb 9 2010, 05:27 PM
Post #3


The Lazy Guy
Group Icon

Group: Revolutionary
Posts: 292
Type: Scripter
RM Skill: Undisclosed




great tutorial! many will learn from this! thumbsup.gif
about the homework, i didn't do it. sweat.gif


__________________________

QUOTE
Better off lazy, at least I'm not exhausted.
Go to the top of the page
 
+Quote Post
   
Shadonn
post Feb 9 2010, 06:55 PM
Post #4


Level 6
Group Icon

Group: Member
Posts: 81
Type: Writer
RM Skill: Undisclosed




This is very helpful man. I'm trying to get the basics down on scripting. It'd be great if I could script everything myself. But I gotta learn first.


__________________________
Go to the top of the page
 
+Quote Post
   
gimis
post Feb 17 2010, 12:58 PM
Post #5


Level 4
Group Icon

Group: Member
Posts: 51
Type: Writer
RM Skill: Undisclosed




QUOTE (The Law G14 @ Feb 9 2010, 03:38 PM) *
Some comments or homework would be nice lol tongue.gif

here ya go
[Show/Hide] asdvavsd



[Show/Hide] asklvblaksv



[Show/Hide] ajksvdb



This post has been edited by gimis: Feb 17 2010, 12:59 PM


__________________________
i suspect nargels...
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 22nd May 2013 - 07:51 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker