Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Of all things, item description

I know this sounds ridiculous, but I was wondering how you can reference and change an items description from in game. Let's say I have my potion's description "Drink me!" Later in the game, for whatever reason, I want to change this to "Don't drink me!". I know for lengthy descriptions I'll just need to make a script and just call it in game.
The problem I'm having is I don't know how to change any item's things, like say description, from in scripts. Also, this would be appreciated for items, weapons, skills, etc. Thank you ahead of time.
 
You need this to make the description accessible from wherever
Code:
# I go above Main
module RPG
  class BaseItem
    attr_accessor :description
  end
end

Then from your script/event/whatever you could do
Code:
$data_items[1].description = "Don't drink me!"
And change the first item's description to "Don't drink me!"

And a simple thing to let you change each item's desciption
Code:
# I also go above Main
module Desc_Change
  # For items
  def self.item_desc(id, description)
    if $data_items[id] == nil
      return
    end
    $data_items[id].description = description
  end
  
  # For weapons
  def self.weapon_desc(id, description)
    if $data_weapons[id] == nil
      return
    end
    $data_weapons[id].description = description
  end
  
  # For armor
  def self.armor_desc(id, description)
    if $data_armors[id] == nil
      return
    end
    $data_armors[id].description = description
  end
end

Making it instead
Code:
Desc_Change.item_desc(1, "Don't drink me!")
Desc_Change.weapon_desc(2, "A sword or something.")
Desc_Change.armor_desc(1, "A kinda terrible shield.")

However however! These changes don't get saved between sessions. You'll need someone more experienced to make any changes get saved along with the save file.

EDIT
I think I figured the saving part out:
Code:
class Scene_File
  #--------------------------------------------------------------------------
  # * Write Save Data
  #     file : write file object (opened)
  #--------------------------------------------------------------------------
  alias desc_change_save :write_save_data
  def write_save_data(file)
    desc_change_save(file)
    Marshal.dump($data_items,          file)
    Marshal.dump($data_weapons,        file)
    Marshal.dump($data_armors,         file)
  end
  #--------------------------------------------------------------------------
  # * Read Save Data
  #     file : file object for reading (opened)
  #--------------------------------------------------------------------------
  alias desc_change_load :read_save_data
  def read_save_data(file)
    desc_change_load(file)
    unless $game_system.version_id != $data_system.version_id
      $data_items        = Marshal.load(file)
      $data_weapons      = Marshal.load(file)
      $data_armors       = Marshal.load(file)
    end
  end
end
Someone who knows more about it should look it over though.
 
Do you want this description to change for ALL the items of that type?  If so, you could create a duplicate of that item in your database with the only difference between the two being the new description.  Then, when you are ready to change the description, have an event that goes through your inventory and removes one of the old item/adds one of the new item, until your entire inventory has had the old item replaced.
 
@BwdYeti
Properties and variables in the RPG modules are always accessors.

@kirbywarrior
I think Juno's method is the best. It's easily doable with a script but, unless you need to change the descriptions of 1000 items, it's easier and more efficient to do what Juno sais.

But if you really want to do it with a script, here's what I would do:
I would start by adding 3 description hashes to game system (for item/weapon/armor).
Then I would cycle through all Items Data and add their descriptions to the hashes:

Code:
@item_description = {}
@weapon_description = {}
@armor_description = {}
for item in $data_items
  @item_description[item.id] = item.description
end
for weapon in $data_weapons
  @weapon_description[weapon.id] = weapon.description
end
for armor in $data_armors
  @armor_description[armor.id] = armor.description
end
These variables must be accessible from anywhere so make them attr_accessors.
You need to add this just before def initialize
Code:
attr_accessor	:item_description
attr_accessor	:weapon_description
attr_accessor	:armor_description

Then, I would modify the RPG::BaseItem class by adding 2 methods. One to reads the description and one to modifies it:
Code:
def description
  return @description if $game_system.nil?
  case self
  when RPG::Item
    if $game_system.item_description[@id] != nil
      return $game_system.item_description[@id]
    end
  when RPG::Weapon
    if $game_system.weapon_description[@id] != nil
      return $game_system.weapon_description[@id]
    end
  when RPG::Armor
    if $game_system.armor_description[@id] != nil
      return $game_system.armor_description[@id]
    end
  end
  return @description
end

Code:
def description=(string)
  @description = string
  return if $game_system.nil?
  case self
  when RPG::Item
    $game_system.item_description[@id] = string
  when RPG::Weapon
    $game_system.weapon_description[@id] = string
  when RPG::Armor
    $game_system.armor_description[@id] = string
  end
end

Now, if you do it right, it should be working. The only thing you need to do to change an item's description is to use
Code:
$data_items[id].description = "my description"
$data_weapons[id].description = "my description"
$data_armors[id].description = "my description"
I did that in 20 minutes, on wordpad, at work. So it's possible that you encounter a few errors.
If you need me to clarify, feel free to ask!

Take care!
-Dargor
 
Ok, I can do some scripting, but I'm not really sure what to do with what you said, Dargor. I understand most of what it means, but I don't know where to put it is the thing. But thank you everyone for your help.

(Heh, you put a y in my name)

Quick Edit: The main reason I want this is so I can have long item/skill descriptions. I'm using a script that allows for 3 or more lines of description, but the database only allows for so many words. But, it is still nice to change item descriptions from in game. I also wanted to learn how to affect database things in general from scripting.
 
The first 2 codes should be added to the Game_System class. The first one has to be added in the initialize method and the second one must be placed just above (Between class Game_System and def initialize).

The next 2 codes should be added to the RPG::BaseItem class, so:
Code:
class RPG::BaseItem
 # code here
end

The last 3 lines of codes should be used in a script call or directly from within the script editor. I suggest to make a common event and modify your items descriptions in it with script calls, then call the event at the begining of the game.
 
class Game_System
  attr_accessor :item_description
  attr_accessor :weapon_description
  attr_accessor :armor_description
  alias item_des initialize
  def initialize
    item_des
    @item_description = {}
    @weapon_description = {}
    @armor_description = {}
    for item in $data_items
      @item_description[item.id] = item.description #<<<<This is the line
    end
    for weapon in $data_weapons
      @weapon_description[weapon.id] = weapon.description
    end
    for armor in $data_armors
      @armor_description[armor.id] = armor.description
    end
  end
end
Here's the code I have for Game System (It didn't even occur to me to put it there, even though you said Game System directly in your first post...) The problem is, an error comes up, saying it doesn't know what a description is.

"undefined method 'description' for Nil:nilclass"

Am I doing something wrong? Here's the entire code:
class Game_System
  attr_accessor :item_description
  attr_accessor :weapon_description
  attr_accessor :armor_description
  alias item_des initialize
  def initialize
    item_des
    @item_description = {}
    @weapon_description = {}
    @armor_description = {}
    for item in $data_items
      @item_description[item.id] = item.description
    end
    for weapon in $data_weapons
      @weapon_description[weapon.id] = weapon.description
    end
    for armor in $data_armors
      @armor_description[armor.id] = armor.description
    end
  end
end

class RPG::BaseItem
  def description
    return @description if $game_system.nil?
    case self
    when RPG::Item
      if $game_system.item_description[@id] != nil
        return $game_system.item_description[@id]
      end
    when RPG::Weapon
      if $game_system.weapon_description[@id] != nil
        return $game_system.weapon_description[@id]
      end
    when RPG::Armor
      if $game_system.armor_description[@id] != nil
        return $game_system.armor_description[@id]
      end
    end
    return @description
  end
  def description=(string)
    @description = string
    return if $game_system.nil?
    case self
    when RPG::Item
      $game_system.item_description[@id] = string
    when RPG::Weapon
      $game_system.weapon_description[@id] = string
    when RPG::Armor
      $game_system.armor_description[@id] = string
    end
  end
end

EDIT: If I should use your code instead of the following one, go ahead and tell me. Otherwise, it seems to work:
class Scene_File < Scene_Base
  alias item_des_save write_save_data
  def write_save_data(file)
    item_des_save(file)
    Marshal.dump($data_items,          file)
  end
  alias item_des_load read_save_data
  def read_save_data(file)
    item_des_load(file)
    $data_items          = Marshal.load(file)
  end
end
 
Everything you did is ok, I'm glad to see you have aliased the initialize method in Game_System! :) That's excellent.
The reason why you have this error is because the Items/Weapons/Armors Data are initializes after Game_System is initialized.
So to fix the problem, you can add this in the initialize method, at the beginning.
Code:
$data_items         = load_data("Data/Items.rvdata")
$data_weapons       = load_data("Data/Weapons.rvdata")
$data_armors        = load_data("Data/Armors.rvdata")
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top