Show item name via coding?

Im trying to get the item name and show in the text box, so instead of changing everytime it's a different item.

It would just get the item name and show.



1629153665341.png
Ruby:
i = @index
i -= 1 while i >= 0 && @list[i].code != 126
if @list[i].code == 126
  name = $data_items[@list[i].parameters[0]].name
else
  name = "Empty"
end
$game_variables[1] = name
wRiEoYF.png
That's...one convoluted way to do it...

Alternatively, add this script anywhere below the "Interpreter" entries and your screenshot example should work immediately.
Code:
class Interpreter
  alias set_item_name_to_game_var command_126
  def command_126
    value = operate_value(@parameters[1], @parameters[2], @parameters[3])
    $game_variables[1] = "#{value} #{$data_items[@parameters[0]].name}"
    set_item_name_to_game_var
  end
  alias set_weapon_name_to_game_var command_127
  def command_127
    value = operate_value(@parameters[1], @parameters[2], @parameters[3])
    $game_variables[1] = "#{value} #{$data_weapons[@parameters[0]].name}"
    set_weapon_name_to_game_var
  end
  alias set_armor_name_to_game_var command_128
  def command_128
    value = operate_value(@parameters[1], @parameters[2], @parameters[3])
    $game_variables[1] = "#{value} #{$data_armors[@parameters[0]].name}"
    set_armor_name_to_game_var
  end
end
I've taken the liberty to add weapons and armors too.
Haha' Nice, KK20. This solution will be more practical, of course.😤
That's...one convoluted way to do it...

Alternatively, add this script anywhere below the "Interpreter" entries and your screenshot example should work immediately.
Code:
class Interpreter
  alias set_item_name_to_game_var command_126
  def command_126
    value = operate_value(@parameters[1], @parameters[2], @parameters[3])
    $game_variables[1] = "#{value} #{$data_items[@parameters[0]].name}"
    set_item_name_to_game_var
  end
  alias set_weapon_name_to_game_var command_127
  def command_127
    value = operate_value(@parameters[1], @parameters[2], @parameters[3])
    $game_variables[1] = "#{value} #{$data_weapons[@parameters[0]].name}"
    set_weapon_name_to_game_var
  end
  alias set_armor_name_to_game_var command_128
  def command_128
    value = operate_value(@parameters[1], @parameters[2], @parameters[3])
    $game_variables[1] = "#{value} #{$data_armors[@parameters[0]].name}"
    set_armor_name_to_game_var
  end
end
I've taken the liberty to add weapons and armors too.
1629212179202.png

I got an syntax error.
my bad, I copied wrong.

It worked fine! thanks!
That's...one convoluted way to do it...

Alternatively, add this script anywhere below the "Interpreter" entries and your screenshot example should work immediately.
Code:
class Interpreter
  alias set_item_name_to_game_var command_126
  def command_126
    value = operate_value(@parameters[1], @parameters[2], @parameters[3])
    $game_variables[1] = "#{value} #{$data_items[@parameters[0]].name}"
    set_item_name_to_game_var
  end
  alias set_weapon_name_to_game_var command_127
  def command_127
    value = operate_value(@parameters[1], @parameters[2], @parameters[3])
    $game_variables[1] = "#{value} #{$data_weapons[@parameters[0]].name}"
    set_weapon_name_to_game_var
  end
  alias set_armor_name_to_game_var command_128
  def command_128
    value = operate_value(@parameters[1], @parameters[2], @parameters[3])
    $game_variables[1] = "#{value} #{$data_armors[@parameters[0]].name}"
    set_armor_name_to_game_var
  end
end
I've taken the liberty to add weapons and armors too.

Theres any code to get the item that is being displayed Icon?
I took the liberty of editing the KK20 script a bit.
I also added a script to put icons in messages, as this is not possible by default in XP. The author is credited.

pbw3FdL.png


Ruby:
#-------------------------------------------------------------------------------
# Draw icon in message box
# for RMXP/RGSS, by mjshi
# OK for use in any project. No configuration necessary.
#-------------------------------------------------------------------------------
# Edits to Window_Message to allow icon-drawing.
# Will conflict with other message window scripts that deal with escape codes.
#-------------------------------------------------------------------------------
# Use the following escape codes in the message box:
# 
# \*[id]    draws the icon of the item
# \I[id]    draws the icon as well as the name of the item
# \i[id]    functionally identical to \I[id]
#-------------------------------------------------------------------------------

class Window_Message
  
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    x = y = 0
    @cursor_width = 0
    # Indent if choice
    if $game_temp.choice_start == 0
      x = 8
    end
    # If waiting for a message to be displayed
    if $game_temp.message_text != nil
      text = $game_temp.message_text
      # Control text processing
      begin
        last_text = text.clone
        text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
      end until text == last_text
      text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
        $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
      end
      # Change "\\\\" to "\000" for convenience
      text.gsub!(/\\\\/) { "\000" }
      # Change "\\C" to "\001" and "\\G" to "\002"
      text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
      text.gsub!(/\\[Gg]/) { "\002" }
      # item icon display
      text.gsub!(/\\[Ii]\[([0-9]+)\]/) { "\003[#{$1}]" }
      text.gsub!(/\\\*\[([0-9]+)\]/) { "\004[#{$1}]" }
      # Get 1 text character in c (loop until unable to get text)
      while ((c = text.slice!(/./m)) != nil)
        # If \\
        if c == "\000"
          # Return to original text
          c = "\\"
        end
        # If \C[n]
        if c == "\001"
          # Change text color
          text.sub!(/\[([0-9]+)\]/, "")
          color = $1.to_i
          if color >= 0 and color <= 7
            self.contents.font.color = text_color(color)
          end
          # go to next text
          next
        end
        # If \G
        if c == "\002"
          # Make gold window
          if @gold_window == nil
            @gold_window = Window_Gold.new
            @gold_window.x = 560 - @gold_window.width
            if $game_temp.in_battle
              @gold_window.y = 192
            else
              @gold_window.y = self.y >= 128 ? 32 : 384
            end
            @gold_window.opacity = self.opacity
            @gold_window.back_opacity = self.back_opacity
          end
          # go to next text
          next
        end
        # If new line text
        if c == "\n"
          # Update cursor width if choice
          if y >= $game_temp.choice_start
            @cursor_width = [@cursor_width, x].max
          end
          # Add 1 to y
          y += 1
          x = 0
          # Indent if choice
          if y >= $game_temp.choice_start
            x = 8
          end
          # go to next text
          next
        end
        if c == "\003"
          text.match(/\[([0-9]+)\]/)
          id = $1.to_i
          name = $data_items[id].name
          text.sub!(/\[([0-9]+)\]/, name)
          bitmap = RPG::Cache.icon($data_items[id].icon_name)
          self.contents.blt(x, y * 32 + 2, bitmap, Rect.new(0, 0, 24, 24))
          x += 24
          next
        end
        
        if c == "\004"
          text.sub!(/\[([0-9]+)\]/, "")
          id = $1.to_i
          bitmap = RPG::Cache.icon($data_items[id].icon_name)
          self.contents.blt(x, y * 32 + 2, bitmap, Rect.new(0, 0, 24, 24))
          x += 24
          next
        end
        
        # Draw text
        self.contents.draw_text(4 + x, 32 * y, 40, 32, c)
        # Add x to drawn text width
        x += self.contents.text_size(c).width
      end
    end
    # If choice
    if $game_temp.choice_max > 0
      @item_max = $game_temp.choice_max
      self.active = true
      self.index = 0
    end
    # If number input
    if $game_temp.num_input_variable_id > 0
      digits_max = $game_temp.num_input_digits_max
      number = $game_variables[$game_temp.num_input_variable_id]
      @input_number_window = Window_InputNumber.new(digits_max)
      @input_number_window.number = number
      @input_number_window.x = self.x + 8
      @input_number_window.y = self.y + $game_temp.num_input_start * 32
    end
  end
end

#==============================================================================
# ** SrHaruno Module
#------------------------------------------------------------------------------
#  --
#==============================================================================

module SrHaruno
  ItemMessageVarID = 1
  ItemIDVarID = 2
end

#==============================================================================
# ** Interpreter (part 4)
#------------------------------------------------------------------------------
#  This interpreter runs event commands. This class is used within the
#  Game_System class and the Game_Event class.
#==============================================================================

class Interpreter
  #--------------------------------------------------------------------------
  # * Change Items
  #--------------------------------------------------------------------------
  alias set_item_name_to_game_var command_126
  def command_126
    data    = $data_items
    value   = operate_value(*@parameters[1,3])
    item_id = @parameters[0]
    $game_variables[SrHaruno::ItemMessageVarID] = "#{value} #{data[item_id].name}"
    $game_variables[SrHaruno::ItemIDVarID] = item_id
    set_item_name_to_game_var
  end
  #--------------------------------------------------------------------------
  # * Change Weapons
  #--------------------------------------------------------------------------
  alias set_weapon_name_to_game_var command_127
  def command_127
    data    = $data_weapons
    value   = operate_value(*@parameters[1,3])
    item_id = @parameters[0]
    $game_variables[SrHaruno::ItemMessageVarID] = "#{value} #{data[item_id].name}"
    $game_variables[SrHaruno::ItemIDVarID] = item_id
    set_weapon_name_to_game_var
  end
  #--------------------------------------------------------------------------
  # * Change Armor
  #--------------------------------------------------------------------------
  alias set_armor_name_to_game_var command_128
  def command_128
    data    = $data_armors
    value   = operate_value(*@parameters[1,3])
    item_id = @parameters[0] 
    $game_variables[SrHaruno::ItemMessageVarID] = "#{value} #{data[item_id].name}"
    $game_variables[SrHaruno::ItemIDVarID] = item_id
    set_armor_name_to_game_var
  end
end
I took the liberty of editing the KK20 script a bit.
I also added a script to put icons in messages, as this is not possible by default in XP. The author is credited.

pbw3FdL.png


Ruby:
#-------------------------------------------------------------------------------
# Draw icon in message box
# for RMXP/RGSS, by mjshi
# OK for use in any project. No configuration necessary.
#-------------------------------------------------------------------------------
# Edits to Window_Message to allow icon-drawing.
# Will conflict with other message window scripts that deal with escape codes.
#-------------------------------------------------------------------------------
# Use the following escape codes in the message box:
#
# \*[id]    draws the icon of the item
# \I[id]    draws the icon as well as the name of the item
# \i[id]    functionally identical to \I[id]
#-------------------------------------------------------------------------------

class Window_Message
 
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    x = y = 0
    @cursor_width = 0
    # Indent if choice
    if $game_temp.choice_start == 0
      x = 8
    end
    # If waiting for a message to be displayed
    if $game_temp.message_text != nil
      text = $game_temp.message_text
      # Control text processing
      begin
        last_text = text.clone
        text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
      end until text == last_text
      text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
        $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
      end
      # Change "\\\\" to "\000" for convenience
      text.gsub!(/\\\\/) { "\000" }
      # Change "\\C" to "\001" and "\\G" to "\002"
      text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
      text.gsub!(/\\[Gg]/) { "\002" }
      # item icon display
      text.gsub!(/\\[Ii]\[([0-9]+)\]/) { "\003[#{$1}]" }
      text.gsub!(/\\\*\[([0-9]+)\]/) { "\004[#{$1}]" }
      # Get 1 text character in c (loop until unable to get text)
      while ((c = text.slice!(/./m)) != nil)
        # If \\
        if c == "\000"
          # Return to original text
          c = "\\"
        end
        # If \C[n]
        if c == "\001"
          # Change text color
          text.sub!(/\[([0-9]+)\]/, "")
          color = $1.to_i
          if color >= 0 and color <= 7
            self.contents.font.color = text_color(color)
          end
          # go to next text
          next
        end
        # If \G
        if c == "\002"
          # Make gold window
          if @gold_window == nil
            @gold_window = Window_Gold.new
            @gold_window.x = 560 - @gold_window.width
            if $game_temp.in_battle
              @gold_window.y = 192
            else
              @gold_window.y = self.y >= 128 ? 32 : 384
            end
            @gold_window.opacity = self.opacity
            @gold_window.back_opacity = self.back_opacity
          end
          # go to next text
          next
        end
        # If new line text
        if c == "\n"
          # Update cursor width if choice
          if y >= $game_temp.choice_start
            @cursor_width = [@cursor_width, x].max
          end
          # Add 1 to y
          y += 1
          x = 0
          # Indent if choice
          if y >= $game_temp.choice_start
            x = 8
          end
          # go to next text
          next
        end
        if c == "\003"
          text.match(/\[([0-9]+)\]/)
          id = $1.to_i
          name = $data_items[id].name
          text.sub!(/\[([0-9]+)\]/, name)
          bitmap = RPG::Cache.icon($data_items[id].icon_name)
          self.contents.blt(x, y * 32 + 2, bitmap, Rect.new(0, 0, 24, 24))
          x += 24
          next
        end
       
        if c == "\004"
          text.sub!(/\[([0-9]+)\]/, "")
          id = $1.to_i
          bitmap = RPG::Cache.icon($data_items[id].icon_name)
          self.contents.blt(x, y * 32 + 2, bitmap, Rect.new(0, 0, 24, 24))
          x += 24
          next
        end
       
        # Draw text
        self.contents.draw_text(4 + x, 32 * y, 40, 32, c)
        # Add x to drawn text width
        x += self.contents.text_size(c).width
      end
    end
    # If choice
    if $game_temp.choice_max > 0
      @item_max = $game_temp.choice_max
      self.active = true
      self.index = 0
    end
    # If number input
    if $game_temp.num_input_variable_id > 0
      digits_max = $game_temp.num_input_digits_max
      number = $game_variables[$game_temp.num_input_variable_id]
      @input_number_window = Window_InputNumber.new(digits_max)
      @input_number_window.number = number
      @input_number_window.x = self.x + 8
      @input_number_window.y = self.y + $game_temp.num_input_start * 32
    end
  end
end

#==============================================================================
# ** SrHaruno Module
#------------------------------------------------------------------------------
#  --
#==============================================================================

module SrHaruno
  ItemMessageVarID = 1
  ItemIDVarID = 2
end

#==============================================================================
# ** Interpreter (part 4)
#------------------------------------------------------------------------------
#  This interpreter runs event commands. This class is used within the
#  Game_System class and the Game_Event class.
#==============================================================================

class Interpreter
  #--------------------------------------------------------------------------
  # * Change Items
  #--------------------------------------------------------------------------
  alias set_item_name_to_game_var command_126
  def command_126
    data    = $data_items
    value   = operate_value(*@parameters[1,3])
    item_id = @parameters[0]
    $game_variables[SrHaruno::ItemMessageVarID] = "#{value} #{data[item_id].name}"
    $game_variables[SrHaruno::ItemIDVarID] = item_id
    set_item_name_to_game_var
  end
  #--------------------------------------------------------------------------
  # * Change Weapons
  #--------------------------------------------------------------------------
  alias set_weapon_name_to_game_var command_127
  def command_127
    data    = $data_weapons
    value   = operate_value(*@parameters[1,3])
    item_id = @parameters[0]
    $game_variables[SrHaruno::ItemMessageVarID] = "#{value} #{data[item_id].name}"
    $game_variables[SrHaruno::ItemIDVarID] = item_id
    set_weapon_name_to_game_var
  end
  #--------------------------------------------------------------------------
  # * Change Armor
  #--------------------------------------------------------------------------
  alias set_armor_name_to_game_var command_128
  def command_128
    data    = $data_armors
    value   = operate_value(*@parameters[1,3])
    item_id = @parameters[0]
    $game_variables[SrHaruno::ItemMessageVarID] = "#{value} #{data[item_id].name}"
    $game_variables[SrHaruno::ItemIDVarID] = item_id
    set_armor_name_to_game_var
  end
end
I got a module with my name
Exactly, today is the day to celebrate. lol
If you have any more questions/problems, let us know.
I took the liberty of editing the KK20 script a bit.
I also added a script to put icons in messages, as this is not possible by default in XP. The author is credited.

pbw3FdL.png


Ruby:
#-------------------------------------------------------------------------------
# Draw icon in message box
# for RMXP/RGSS, by mjshi
# OK for use in any project. No configuration necessary.
#-------------------------------------------------------------------------------
# Edits to Window_Message to allow icon-drawing.
# Will conflict with other message window scripts that deal with escape codes.
#-------------------------------------------------------------------------------
# Use the following escape codes in the message box:
#
# \*[id]    draws the icon of the item
# \I[id]    draws the icon as well as the name of the item
# \i[id]    functionally identical to \I[id]
#-------------------------------------------------------------------------------

class Window_Message
 
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    x = y = 0
    @cursor_width = 0
    # Indent if choice
    if $game_temp.choice_start == 0
      x = 8
    end
    # If waiting for a message to be displayed
    if $game_temp.message_text != nil
      text = $game_temp.message_text
      # Control text processing
      begin
        last_text = text.clone
        text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
      end until text == last_text
      text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
        $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
      end
      # Change "\\\\" to "\000" for convenience
      text.gsub!(/\\\\/) { "\000" }
      # Change "\\C" to "\001" and "\\G" to "\002"
      text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
      text.gsub!(/\\[Gg]/) { "\002" }
      # item icon display
      text.gsub!(/\\[Ii]\[([0-9]+)\]/) { "\003[#{$1}]" }
      text.gsub!(/\\\*\[([0-9]+)\]/) { "\004[#{$1}]" }
      # Get 1 text character in c (loop until unable to get text)
      while ((c = text.slice!(/./m)) != nil)
        # If \\
        if c == "\000"
          # Return to original text
          c = "\\"
        end
        # If \C[n]
        if c == "\001"
          # Change text color
          text.sub!(/\[([0-9]+)\]/, "")
          color = $1.to_i
          if color >= 0 and color <= 7
            self.contents.font.color = text_color(color)
          end
          # go to next text
          next
        end
        # If \G
        if c == "\002"
          # Make gold window
          if @gold_window == nil
            @gold_window = Window_Gold.new
            @gold_window.x = 560 - @gold_window.width
            if $game_temp.in_battle
              @gold_window.y = 192
            else
              @gold_window.y = self.y >= 128 ? 32 : 384
            end
            @gold_window.opacity = self.opacity
            @gold_window.back_opacity = self.back_opacity
          end
          # go to next text
          next
        end
        # If new line text
        if c == "\n"
          # Update cursor width if choice
          if y >= $game_temp.choice_start
            @cursor_width = [@cursor_width, x].max
          end
          # Add 1 to y
          y += 1
          x = 0
          # Indent if choice
          if y >= $game_temp.choice_start
            x = 8
          end
          # go to next text
          next
        end
        if c == "\003"
          text.match(/\[([0-9]+)\]/)
          id = $1.to_i
          name = $data_items[id].name
          text.sub!(/\[([0-9]+)\]/, name)
          bitmap = RPG::Cache.icon($data_items[id].icon_name)
          self.contents.blt(x, y * 32 + 2, bitmap, Rect.new(0, 0, 24, 24))
          x += 24
          next
        end
       
        if c == "\004"
          text.sub!(/\[([0-9]+)\]/, "")
          id = $1.to_i
          bitmap = RPG::Cache.icon($data_items[id].icon_name)
          self.contents.blt(x, y * 32 + 2, bitmap, Rect.new(0, 0, 24, 24))
          x += 24
          next
        end
       
        # Draw text
        self.contents.draw_text(4 + x, 32 * y, 40, 32, c)
        # Add x to drawn text width
        x += self.contents.text_size(c).width
      end
    end
    # If choice
    if $game_temp.choice_max > 0
      @item_max = $game_temp.choice_max
      self.active = true
      self.index = 0
    end
    # If number input
    if $game_temp.num_input_variable_id > 0
      digits_max = $game_temp.num_input_digits_max
      number = $game_variables[$game_temp.num_input_variable_id]
      @input_number_window = Window_InputNumber.new(digits_max)
      @input_number_window.number = number
      @input_number_window.x = self.x + 8
      @input_number_window.y = self.y + $game_temp.num_input_start * 32
    end
  end
end

#==============================================================================
# ** SrHaruno Module
#------------------------------------------------------------------------------
#  --
#==============================================================================

module SrHaruno
  ItemMessageVarID = 1
  ItemIDVarID = 2
end

#==============================================================================
# ** Interpreter (part 4)
#------------------------------------------------------------------------------
#  This interpreter runs event commands. This class is used within the
#  Game_System class and the Game_Event class.
#==============================================================================

class Interpreter
  #--------------------------------------------------------------------------
  # * Change Items
  #--------------------------------------------------------------------------
  alias set_item_name_to_game_var command_126
  def command_126
    data    = $data_items
    value   = operate_value(*@parameters[1,3])
    item_id = @parameters[0]
    $game_variables[SrHaruno::ItemMessageVarID] = "#{value} #{data[item_id].name}"
    $game_variables[SrHaruno::ItemIDVarID] = item_id
    set_item_name_to_game_var
  end
  #--------------------------------------------------------------------------
  # * Change Weapons
  #--------------------------------------------------------------------------
  alias set_weapon_name_to_game_var command_127
  def command_127
    data    = $data_weapons
    value   = operate_value(*@parameters[1,3])
    item_id = @parameters[0]
    $game_variables[SrHaruno::ItemMessageVarID] = "#{value} #{data[item_id].name}"
    $game_variables[SrHaruno::ItemIDVarID] = item_id
    set_weapon_name_to_game_var
  end
  #--------------------------------------------------------------------------
  # * Change Armor
  #--------------------------------------------------------------------------
  alias set_armor_name_to_game_var command_128
  def command_128
    data    = $data_armors
    value   = operate_value(*@parameters[1,3])
    item_id = @parameters[0]
    $game_variables[SrHaruno::ItemMessageVarID] = "#{value} #{data[item_id].name}"
    $game_variables[SrHaruno::ItemIDVarID] = item_id
    set_armor_name_to_game_var
  end
end
1629337242095.png

Got a no method error
Can you send an image of the event causing the error?
1629337954959.png

Same thing just using the \I
I tried to replicate the error here, but without success.
The error is from the script to show icons in messages, btw. You can try to find another script like that.
I tried to replicate the error here, but without success.
The error is from the script to show icons in messages, btw. You can try to find another script like that.
if c == "\003" text.match(/\[([0-9]+)\]/) id = $1.to_i name = $data_items[id].name text.sub!(/\[([0-9]+)\]/, name) bitmap = RPG::Cache.icon($data_items[id].icon_name) self.contents.blt(x, y * 32 + 2, bitmap, Rect.new(0, 0, 24, 24)) x += 24 next end

Points to this part. the 'name' is missing
1629339323214.png

Original thread: https://forums.rpgmakerweb.com/threads/show-item-name-via-coding.139659/