Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial system
#1
Tutorial system
by Jimmie
Aug 14 2009

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Modern algebra once made this awesome script which lets you (relatively) easily make a tutorial for any scene. Upon request, I've now ported this script for XP. I have only done simple testing, so please alert me to any issues you discover so I can fix them as soon as possible n_n;;

For those not familiar with the original script, this lets you open up a scene and then simulate user input using the "Set move route" or "Control variables" event commands in a common event. You can also use the "Show text" command to explain what you're up to.

Code:
#==============================================================================
# Scene Tutorial
# Version 1.0
# Author: modern algebra (rmrk.net)
# Date: September 15, 2008
# Modified by Jimmie for RMXP, 14 of August 2009
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Description:
# This script allows you to freeze user input for a scene and run a special
# common event that controls input. Effectively, this allows you to run a
# scene and direct a tutorial to that scene that explains what the scene is.
# So, if you ever wanted to give the players to your game a tutorial on
# using the Menu scene, then this is the script for you.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Instructions:
# Okay, this script can be slightly difficult to use, so you have to pay
# careful attention to the instructions.
#
# To start a tutorial, you must use a call script with this code:
#
# $tutorial.start (scene, common event id)
#
# where scene is the name of the scene to call, (like Scene_Menu or
# Scene_Battle) and common event ID is the ID of the common event that
# controls the tutorial. Now, that's the easy part. Setting up the controller
# common event will be tricky at first, but once you get the hang of it,
# you'll be fine. Now, read the instructions very carefully:
#
# The Standard Wait Variable - You set what Variable this will be at line
# 200. The value of this variable determines how many frames to wait for
# after each command.
#
# The controller common event is similar to a regular common event in some
# ways but many of the commands will be unavailable to you while others will
# be irrelevant and others still will have a different effect than you would
# expect. In the instructions, I will go over the functions of what will be
# the most important commands in making a scene tutorial, but I just wanted
# to warn you that many commands will not work as you expect them to. (For
# instance, pictures, screen tone etc... will only work in a battle or map
# tutorial). So, depending on how the scene is built, some things are
# possible while others are not. Note, however, that in a number of cases,
# you can simulate the effect that is not possible. That being said, it can
# get quite convoluted, but that was as far as I was willing to go with this
# script. I apologize for the difficulty.
#
# Anyway, there are a couple of specialized commands that have their function
# changed from what they would normally do. These are:
#
# Control Variable
# Set Move Route
#
# These have been changed so that rather than do what they would normally,
# they instead interpret input. Since player input is frozen during a
# tutorial, scene movement is handled by you, the game creator. It is done
# through these two commands. This can be rather non-intuitive, but for each
# value of 0 through 19, a button is attached. It is similar for Set Move
# Route, but let's go over the variable way of setting input first.
#
# To set it, it must be a single variable set to a constant. If any other
# option is chosen, then the Control Variable command will function normally.
# Also, the control variable command will behave normally if the variable you
# choose is the one you choose for setting standard wait time. Anyway, here
# is the list of values and their effects:
#
# 0 - Down Cursor
# 1 - Left Cursor
# 2 - Right Cursor
# 3 - Up Cursor
# 4 - Button A
# 5 - Button B
# 6 - Button C
# 7 - Button X
# 8 - Button Y
# 9 - Button Z
# 10 - Button L
# 11 - Button R
# 12 - SHIFT
# 13 - CTRL
# 14 - ALT
# 15 - F5
# 16 - F6
# 17 - F7
# 18 - F8
# 19 - F9
#
# If you want to wait some frames, the Wait command will work normally.
#
# Set Move Route has a similar set of moves attached. They are:
# Move Down - Down Cursor
# Move Left - Left Cursor
# Move Right - Right Cursor
# Move Up - Up Cursor
# Move Lower Left - Button A
# Move Lower Right - Button B
# Move Upper Left - Button C
# Move Upper Right - Button X
# Move at Random - Button Y
# Move Toward Player - Button Z
# Move Away from Player - Button L
# One Step Forward - Button R
# One Step Backward - SHIFT
# Jump - CTRL
# Wait - Waits for however many frames
# Turn Down - ALT
# Turn Left - F5
# Turn Right - F6
# Turn Up - F7
# Turn 90 Left - F8
# Turn 90 Right - F9
#
# So basically, using those commands will make the scene react as if the
# corresponding button had just been pressed.
#==============================================================================
# *** Input
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Summary of Changes:
# aliased method - trigger?, press?, repeat?
#==============================================================================

module Input
  class << self
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * Frame Update
    #````````````````````````````````````````````````````````````````````````
    # Updates tutorial as well if it exists. It does it in Input as all scenes
    # update Input every frame
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    alias modalg_tutorials_update_9rt update
    def update
      $tutorial.update if $tutorial.active?
      # Run Original Method
      modalg_tutorials_update_9rt
    end
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * Trigger?
    #````````````````````````````````````````````````````````````````````````
    # If Tutorial is running, freezes input and accepts only tutorial input
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    alias modalg_tut_frz_inpt_trig_dj5 trigger?
    def trigger? (key)
      return $tutorial.button == key if $tutorial.active? && !$tutorial.upd_input
      # Run Original Method
      modalg_tut_frz_inpt_trig_dj5 (key)
    end
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * Repeat?
    #````````````````````````````````````````````````````````````````````````
    # If Tutorial is running, freezes input and accepts only tutorial input
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    alias modalg_rpt_tutorial_upd_8fn repeat?
    def repeat? (key)
      return $tutorial.button == key if $tutorial.active? && !$tutorial.upd_input
      # Run Original Method
      modalg_rpt_tutorial_upd_8fn (key)
    end
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # * Press?
    #````````````````````````````````````````````````````````````````````````
    # If Tutorial is running, freezes input and accepts only tutorial input
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    alias modalg_tut_prs_frz_inpt_9nfg press?
    def press? (key)
      return $tutorial.button == key if $tutorial.active? && !$tutorial.upd_input
      # Run Original Method
      modalg_tut_prs_frz_inpt_9nfg (key)
    end
  end
end

#==============================================================================
# ** Tutorial Guide
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# This class handles the interpretation of the common event for a tutorial
#==============================================================================

class Game_TutorialGuide < Interpreter
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  # * Constant
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  # STANDARD WAIT VARIABLE is the ID of the event variable that holds a
  # standard wait between input commands. Basically, if this is set to 2,
  # then Variable with ID 2 will control the wait between actions. So, if
  # Variable with ID 2 is set to 4, then it will wait four frames before
  # executing the next command in the common event
  STANDARD_WAIT_VARIABLE = 2
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  def initialize
    super
    @wait_frames = 0
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  # * Control Variable
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  def command_122
    if @parameters[3] == 0 || @parameters[0] == STANDARD_WAIT_VARIABLE
      command_input (@parameters[4] + 1)
    else
      super
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  # * Set Move Route
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  def command_209
    @move_route = @parameters[1].list
    @moveroute_index = 0
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  # * Wait
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  def command_106
    command_wait (@params[0])
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  # * Frame Update
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  def update
    # Wait
    if @wait_frames > 0
      @wait_frames -= 1
      return
    end
    # Execute Move Route Input
    unless @move_route.nil?
      loop do
        # Move on once move route exhausted
        if @moveroute_index >= (@move_route.size - 1)
          @move_route = nil
          @moveroute_index = 0
          break
        end
        # Execute Input command
        command_move (@move_route[@moveroute_index])
        @moveroute_index += 1
        return if @wait_frames > 0
      end
    end
    return false if @list.nil?
    return if !execute_command # Execute event command
    @index += 1
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  # * Command Input
  # button_code : the key a button corresponds to.
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  def command_input (button_value)
    $tutorial.button = case button_value
      when 1 then Input::DOWN # Cursor Down
      when 2 then Input::LEFT # Cursor Left
      when 3 then Input::RIGHT # Cursor Right
      when 4 then Input::UP # Cursor Up
      when 5 then Input::A # Press A
      when 6 then Input::B # Press B
      when 7 then Input::C # Press C
      when 8 then Input::X # Press X
      when 9 then Input::Y # Press Y
      when 10 then Input::Z # Press Z
      when 11 then Input::L # Press L
      when 12 then Input::R # Press R
      when 13 then Input::SHIFT # Press SHIFT
      when 14 then Input::CTRL # Press CTRL
      when 15 then Input::ALT # Press ALT
      when 16 then Input::F5 # Press F5
      when 17 then Input::F6 # Press F6
      when 18 then Input::F7 # Press F7
      when 19 then Input::F8 # Press F8
      when 20 then Input::F9 # Press F9
    end
    @wait_frames = $game_variables[STANDARD_WAIT_VARIABLE]
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  # * Command Move
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  def command_move (command)
    command_input (command.code) if command.code < 15
    command_wait (command.parameters[0] - 1) if command.code == 15
    command_input (command.code - 1) if command.code.between? (16, 21)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  # * Command Wait
  # duration : the number of frames to wait
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  def command_wait (duration)
    # Wait Frames - Subtract Standard wait frames tacked on by previous command
    @wait_frames = duration
  end
end

#==============================================================================
# ** Tutorial
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# This class basically interprets a common event and navigates a scene by the
# codes used in that common event
#==============================================================================

class Tutorial
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  # * Public Instance Variables
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  attr_reader :upd_input
  attr_accessor :button
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  def initialize
    # Initialize variables
    @button = false
    @upd_input = false
    @active = false
    @tutorial_guide = Game_TutorialGuide.new
    @index = 0
    @wait_frames = 0
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Start
  # scene : the scene to guide through
  # common_event_id : the navigation common event
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def start (scene, common_event_id)
    # Get Common Event
    @tutorial_guide.setup ($data_common_events[common_event_id].list, 1)
    # Initialize Scene
    $scene = scene.new
    @active = true
    # Initialize Message window here because uses $game variables.
    if @message_window.nil?
      @message_window = Window_Message.new
      @message_window.z = 210
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  # * Update
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  def update
    @button = nil
    @upd_input = true
    @message_window.update
    @upd_input = false
    if $game_temp.message_text != nil or @message_window.visible
      return
    end
    @active = false if @tutorial_guide.update == false
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  # * Active?
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  def active?
    return @active
  end
end

#==============================================================================
# ** Scene_Title
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Summary of Changes:
# aliased method - initialize
#==============================================================================

class Scene_Title
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  # * Initialize
  #``````````````````````````````````````````````````````````````````````````
  # Initialize $tutorial
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  alias modalg_tutorial_scenes_ldb_init_nf4 initialize
  def initialize
    # Initialize Tutorial
    $tutorial = Tutorial.new
    # Run Original Method
    modalg_tutorial_scenes_ldb_init_nf4
  end
end

//Jimmie
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Dynamic Weather and Time System ThallionDarkshine 0 2,466 05-25-2012, 01:00 PM
Last Post: ThallionDarkshine
  New and Easy Cache system azrith001 0 2,400 09-02-2008, 01:00 PM
Last Post: azrith001
  Vehicle System El Conductor 0 2,379 12-22-2007, 01:00 PM
Last Post: El Conductor
  IMPROVED Fog of War System Samo the thief 0 2,145 05-06-2007, 01:00 PM
Last Post: Samo the thief
  Weight Equip System and Limit Samo the thief 0 2,186 01-29-2007, 01:00 PM
Last Post: Samo the thief
  Prize Points System Dark Ruby 0 2,189 01-28-2007, 01:00 PM
Last Post: Dark Ruby
  Export and Import System EmilyAnnCoons 0 2,081 12-29-2006, 01:00 PM
Last Post: EmilyAnnCoons
  Hawk's Mouse Control System Hawk-McKain 0 2,366 11-05-2006, 01:00 PM
Last Post: Hawk-McKain
  Time / Day/Night System mikah 0 2,023 09-26-2006, 01:00 PM
Last Post: mikah
  Unleash System Vandette 0 2,114 11-06-2005, 01:00 PM
Last Post: Vandette



Users browsing this thread: