Lord Vectra

Master Eventer
Veteran
Joined
Dec 6, 2015
Messages
328
Reaction score
416
First Language
English
Primarily Uses
RMVXA
Here's the link to the script (but I think you need to log in so I'll have it below too): Link

Ruby:
#==============================================================================
# ** Awesome "Show Choices"
# Version 1.0 by Jimmie 23 July 2009
# Version 1.0b by Jimmie 23 July 2009
# ---- For the UMS
#------------------------------------------------------------------------------
# Groups all immediately following choices into the first one (to allow an
# arbitrary amount of options) and lets the developer specify requirements for
# whether or not an option is to be shown to the player.
#==============================================================================

=begin

INSTRUCTIONS
===============================================================================
Whenever a "Show Choice" command comes up, the game will keep scanning the
event for more of them, and group them all into a single choice.
To avoid grouping two choices, you can use any other event command between
them, including comments.
Codes are written directly into the choice between curly brackets like so:
  {code}Choice
Each code needs it's own set of brackets, and codes can appear anywhere in the
choice text. A choice will only be shown if it passes ALL requirements.

Please note: With this script installed, the "Cancel" setting of show choices
will always be set to "Disallow".
-------------------------------------------------------------------------------

CODES
===============================================================================
N: Any number
M: Any number
O: A comparison operator (">", "<", ">=, "<=" or "==")
    "=" will be replaced with "==" by the script
V: A "V".
S: An "S"
R: An "R"
!: An "!"

* N     : Shown only if SWITCH #N is ON
* !N    : Shown only if SWITCH #N if OFF
* NOM   : Shown only if the comparison between VARIABLE #N and the NUMBER M
          evaluates to TRUE
* !NOM  : Shown only if the comparison between VARIABLE #N and the NUMBER M
          evaluates to FALSE
* NOVM  : Shown only if the comparison between VARIABLE #N and VARIABLE #M
          evaluates to TRUE
* !NOVM : Shown only if the comparison between VARIABLE #N and VARIABLE #M
          evaluates to FALSE
* SN    : Shown only if the contents of @script[N] is true
* RN    : Is replaced by the contents of @replace[N]. Replacements can be
          recursive depending on the RECURSIVE_REPLACEMENTS setting below.

If you ever feel the need to write a code without having it used (ie escaping
the code) let me know and I'll fix it. For now there is no such functionality.
-------------------------------------------------------------------------------


CONFIGURATION
===============================================================================
=end         
# If true, the script will check for replacements again if it performs any on
# the original choice:
RECURSIVE_REPLACEMENTS = false

# If true, the script will reduce the height of the message box when there
# aren't enough lines to fill it (it already increases size when there are
# too many lines...)
TRIM_SIZE = false
#------------------------------------------------------------------------------
# Nothing below this should need to be modified
#==============================================================================

#==============================================================================
# ** Interpreter
# Modified by Jimmie for Awesome "Show Choices" 23 July 2009
#==============================================================================
class Interpreter
  # Constants for code group indexes
  ALL = 0
  NEGATE = 1
  ID = 2
  OPERATOR = 3
  COMPARISON = 4
  SCRIPT = 5
 
  # This method checks whether a choice should be included
  # and removes the codes from the choice text
  def include_choice?(choice_text)
    @variable = 0
    modifier = ""
    value = 0
    new_text = choice_text.clone
    
    # Do replaces first, since it'll have to start over if there is one
    replaced = false
    replaces = new_text.scan(/({R(\d+)})/)
    replaces.each do |replace|
      new_text.sub!(replace[0], @replace[replace[1].to_i])
      replaced = true
    end
    
    # If replacing recursively, start over with new string
    # otherwise keep going
    if replaced && RECURSIVE_REPLACEMENTS
      return include_choice?(new_text)
    end
    
    matches = new_text.scan(/({(!)?(\d+)(?:([<>=]+)(V?\d+))?}|{S(\d+)})/)
    matches.each do |match|
      # Is there a script code?
      if match[SCRIPT] != nil
        if @script[SCRIPT]
          new_text.sub!(match[ALL], "")
        else
          return false
        end
        
      # Otherwise we must have matched a switch or variable code
      
      # If there's no operator, it can't be a variable code
      elsif match[OPERATOR] == nil
        if ($game_switches[match[ID].to_i] == true) ^ (match[NEGATE] != nil)
          new_text.sub!(match[ALL], "")
        else
          return false
        end
        
      # If there is an operator, it's a variable code
      else
        first = $game_variables[match[ID].to_i]
        second = 0
        # Are we comparing with a variable...
        if match[COMPARISON][0,1].downcase == 'v'
          second = $game_variables[(match[COMPARISON][1...-1]).to_i]
        # ...Or an immediate value?
        else
          second = match[COMPARISON].to_i
        end

        if match[OPERATOR] == "="
          match[OPERATOR] = "=="
        end
          
        # Perform the comparison
        eval_string = first.to_s + match[OPERATOR] + second.to_s
        if (eval(eval_string)) ^ (match[NEGATE] != nil)
          new_text.sub!(match[ALL], "")
        else
          return false
        end
      end
    end
    
    return new_text   
  end
 
 
  #--------------------------------------------------------------------------
  # * Setup Choices
  #--------------------------------------------------------------------------
  def setup_choices(from_index)
    if @list[from_index].code != 102
      return
    end
    index = from_index
    $game_temp.choice_max = 0
    $game_temp.choice_start = $game_temp.message_lines
    @branch_table = []
    @index_table = []
    last_choice_index = index
    while index < @list.size
      action = @list[index]
      if action.code == 102 # Show choice
        last_choice_index = index
        index += 1
        new_texts = []
        for i in 0...action.parameters[0].size do
          take = include_choice?(action.parameters[0][i])
          if take
            new_texts.push(take)
            @index_table.push(index)
            @branch_table.push(i)
          end
        end
 
        $game_temp.choice_max += new_texts.size
        for text in new_texts
          $game_temp.message_text += text + "\n"
        end
        
      elsif action.code == 402 #When [Choice]: statement
        index += 1
        indent = 1 #Already in one show choice
        while indent > 0 # Skip until this show choice ends
          if @list[index].code == 404 #Show choice end
            indent -= 1
          elsif @list[index].code == 102 #Nested show choice
            indent += 1           
          end
          index += 1
        end
      else
        break
      end
    end
    $game_temp.message_lines += $game_temp.choice_max
    
    # Set cancel processing to Disallow
    $game_temp.choice_cancel_type = 0
    # Set callback
    current_indent = @list[last_choice_index].indent
    $game_temp.choice_proc = Proc.new { |n| choice_branch(n, current_indent)}
    
  end
 
  # Called when a choice is made to decide where the event will jump
  def choice_branch(choice, indent)
    @index = @index_table[choice]
    @branch[indent] = @branch_table[choice]
  end
 
  #--------------------------------------------------------------------------
  # * Show Text
  #--------------------------------------------------------------------------
  def command_101
    # If other text has been set to message_text
    if $game_temp.message_text != nil
      # End
      return false
    end
    # Set message end waiting flag and callback
    @message_waiting = true
    $game_temp.message_proc = Proc.new { @message_waiting = false }
    # Set message text on first line
    $game_temp.message_text = @list[@index].parameters[0] + "\n"
    $game_temp.message_lines = 1
    # Loop
    loop do
      # If next event command text is on the second line or after
      if @list[@index+1].code == 401
        # Add the second line or after to message_text
        $game_temp.message_text += @list[@index+1].parameters[0] + "\n"
        $game_temp.message_lines += 1
      # If event command is not on the second line or after
      else
        if $game_temp.message_lines < 4
          # Check for choices, if none check input number
          if !setup_choices(@index + 1)
            # If next event command is input number
            if @list[@index+1].code == 103
              # We know it fits
              @index += 1
              # Number input setup
              $game_temp.num_input_start = $game_temp.message_lines
              $game_temp.num_input_variable_id = @list[@index].parameters[0]
              $game_temp.num_input_digits_max = @list[@index].parameters[1]
            end
          end
        end
        # No more message lines
        return true
      end
      # Advance index
      @index += 1
    end
  end
 
  #--------------------------------------------------------------------------
  # * Show Choices
  #--------------------------------------------------------------------------
  def command_102
    # If text has been set to message_text
    if $game_temp.message_text != nil
      # End
      return false
    end
    $game_temp.message_lines = 0
    # If this choice has already been displayed
    if @list[@index - 1].code == 404
      # Skip until it ends
      while @list[@index].code != 404
        @index += 1
      end
      return
    end
    # Set message end waiting flag and callback
    @message_waiting = true
    $game_temp.message_proc = Proc.new { @message_waiting = false }
    # Choices setup
    $game_temp.message_text = ""
    $game_temp.choice_start = 0
    setup_choices(@index)
    # Continue
    return true
  end
end

#==============================================================================
# ** Game_Temp
# Modified by Jimmie for Awesome "Show Choices" 23 July 2009
#==============================================================================
class Game_Temp
  attr_accessor :message_lines
  alias jr_mc_initialize initialize
  def initialize
    jr_mc_initialize
    @message_lines = 0
  end
end

What I need is for it to also check for global variables. That's pretty much about it. So if I do something like "$RPG = 1" in a script somewhere, it'd be nice to be able to have a choice appear or not appear based on that global variable.

While I'm here, can anyone explain how to use @script[N] and @replace[N] because Demo is no longer available, and I still have no clue what they actually do or how they work.
 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
480
Reaction score
195
First Language
English
Primarily Uses
RMXP
I can tell that the "script" logic is wrong. Make this correction I point out below:
Ruby:
      # Is there a script code?
      if match[SCRIPT] != nil
        if @script[SCRIPT] #<========== should actually be: if @script[match[SCRIPT].to_i]
          new_text.sub!(match[ALL], "")
        else
          return false
        end

For both script and replace, my guess is that you're supposed to do a script call immediately before the show choices to initialize their values. With scripts for example,
1657247829269.png
Assuming you first initialize @script = [] (which this script really should have done...another mistake to tally), you can initialize this array with true/false values that will persist throughout different events. However, this will not persist after the player closes the game and starts it back up again, so it'd be advisable to always do these script calls prior to every choice when you're actually going to use them.

Meanwhile with replace, the idea is that you do (again, assuming you have @replace = [] first somewhere)
Code:
@replace[1] = 'New Text'
and now the choice "{R1} Choice 1" will become "New Text Choice 1".
Or even do
Code:
@replace[1] = '{1}'
and now your {R1} has turned into a "is switch ID 1 ON" conditional.

The RECURSIVE_REPLACEMENTS configuration basically means you could do
Code:
@replace[1] = '{R2}'
@replace[2] = 'Recursive!'
and now it will essentially evaluate your choice as "{R2} Choice 1" to then become "Recursive! Choice 1".

Seeing as you might want to use the script feature, what you're going to want to do is add this aliased initialize method here:
Ruby:
class Interpreter
  # Constants for code group indexes
  ALL = 0
  NEGATE = 1
  ID = 2
  OPERATOR = 3
  COMPARISON = 4
  SCRIPT = 5
 
  alias init_for_scripts_and_replace initialize
  def initialize(*args)
    @script = []
    @replace = []
    init_for_scripts_and_replace(*args)
  end
and you should be good to go to use the examples I shared above.
 

Latest Threads

Latest Posts

Latest Profile Posts

GABposterworkhardest.png
Just about finished I reckon.
This could probably be an entire thread, but it’s really interesting how replaying a game several years later can change how you relate to a character. I think Tidus from FFX got such a bad rap. I getchu. Completely different reaction as an adult now.
As you see, I still enjoy writing tutorials. Is there anything specific you want to see? (I know mapping and editing/resource making is usually popular, but those are very broad topics)
Well, I wanted to expand player battlers visually and now have 3 sheets and counting for each of my players party.
1. Regular sheet
2. The character has turned stone sheet.
3. Using potions sheet.

Technically the main hero has 4 since he starts with a wooden sword, and I felt that the battler should reflect that until he gets a metal one.

Right back to the RM game dev grind in about 15 minutes. :LZSexcite:

Forum statistics

Threads
131,739
Messages
1,222,819
Members
173,493
Latest member
SykkunoSimp
Top