Changing Database Entry in Script?

Pandappuccino

Depressed Panda
Member
Joined
Aug 2, 2020
Messages
6
Reaction score
18
First Language
English
Primarily Uses
RMVXA
So I'm following Slip into Ruby to try to create a window that will work like a character database, giving information on the characters that the player will encounter in my game. This is primarily so I can make it look how I envision it, rather than fighting with other scripts.

However, I've run into a small snag. I want the player to be able to customize their character a bit (their name, gender, etc.), so I've left the name of the first actor blank. When the game starts up, the player inputs a name for the character. However, in the database, I can't figure out how to get the first entry to no longer be blank. Do I need to set a variable that holds the new name? And how would I call that?

I included a couple of screenshots to illustrate what I mean. I have a quickstart set up that creates a "default" character with a proper name and whatnot, but it doesn't reflect in the database. The only thing I can think is that the value isn't changed in $data_actors. Is there a script call to set that?

Note, I'm an absolute novice with Ruby. I'm basically customizing the Bestiary script from Slip Into Ruby.
 

Attachments

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
287
Reaction score
71
First Language
English
Primarily Uses
RMXP
Well, the script you've been using would be helpful here.
Hrm, when exactly are you opening that menu? Before the name is set? After the player has chosen his or her name? Later on in game?
The answer might change depending on WHEN you'd need to grab that name and how you've implemented the menu.
Usually you'd only let the player assign the First Actor's name so the guide should have mentioned it. That would work after the player proceeds to the game stage itself.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
30,907
Reaction score
7,447
First Language
German
Primarily Uses
RMMV
for the engine, the database is read-only, you simply can't change its entries with script commands.

look for one of those scripts that create a dynamic database. It requires a lot of changes to be able to change the database during games, but that work has been done by others already.
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
287
Reaction score
71
First Language
English
Primarily Uses
RMXP
Well, Andar that's half true. At least during testing and by distributing a non compressed game, you CAN alter the Actors.rxdata or rvdata or rvdata2 file. You see, you CAN change its value but in game. Once you stop playing or change the saved game, that's it. No more custom names.
The OP was right about having to save the custom names in one or more variables.
There's no mandatory need to use a dynamic database in the same sense as $data_actors for instance, a custom script that just stores name values could also handle it.
 
Last edited:

Pandappuccino

Depressed Panda
Member
Joined
Aug 2, 2020
Messages
6
Reaction score
18
First Language
English
Primarily Uses
RMVXA
I've actually been trying to write the code from (sort of) scratch, using the tutorial from Slip Into Ruby for making a Bestiary to create the framework of the roster screen. The roster is accessed from an event for now (I might implement it into the menu using Yanfly's menu scripts), and the character information is first saved at the very start of the game--during the introductory scene you input your character's name and choose a gender. After the name is entered and changed it's set to a variable, but from there I'm not sure how to go about inserting that information as part of the data for the menu's list.

It's very bare-bones right now but this is the code I have so far from following the tutorial:
Ruby:
class Scene_Roster < Scene_MenuBase
  def start
    super
    @list_window = Window_Roster.new(0, 0, 150)
    @list_window.set_handler(:cancel,  method(:return_scene))
  end
end

class Window_Roster < Window_Selectable
  def initialize(x, y, width)
    super(x, y, width, Graphics.height - y - ($data_actors.length * 29))
    data = []
    self.index = 0
    activate
    refresh
  end
 
  def item
    @data && index >= 0 ? @data[index] : nil
  end
 
  def item_max
    @data ? @data.size : 1
  end
    
  def make_item_list
    @data = $data_actors.compact
  end
 
  def draw_item(index)
    item = @data[index]
    if item
      rect = item_rect_for_text(index)
      draw_text(rect, item.name)
    end
  end
 
  def refresh
    make_item_list
    create_contents
    draw_all_items
  end
end

I don't know if there's a way to "insert" the name into the menu, or if there is one and it's very easy but I don't know how to do it.
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
287
Reaction score
71
First Language
English
Primarily Uses
RMXP
How exactly did you save the actor's name? That could is key to solving your issue.
As an alternative, you could use $game_actors instead of $data_actors for names.
Game_Actors class should make a "copy" of the data found in $data_actors.
 

Pandappuccino

Depressed Panda
Member
Joined
Aug 2, 2020
Messages
6
Reaction score
18
First Language
English
Primarily Uses
RMVXA
How exactly did you save the actor's name? That could is key to solving your issue.
As an alternative, you could use $game_actors instead of $data_actors for names.
I used a script call:
Code:
$game_variables[7] = $game_party.leader.name
(The other variables are used for determining the player's starting class, and for getting map data for a common event.)

However, now I'm running into a problem when I change it to $game_actors in that it's saying there's no method for "size" or "compact". Do I have to define these methods from scratch as well?
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
287
Reaction score
71
First Language
English
Primarily Uses
RMXP
$game_actors[ActorID].name can be accessed in game the same way any other Actor is. Take advantage of it.
Right. It doesn't include such methods. Why exactly were you using them? Aren't you supposed to display all the names the first time you open your menu?
 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
258
Reaction score
95
First Language
English
Primarily Uses
RMXP
Why exactly were you using them? Aren't you supposed to display all the names the first time you open your menu?
Because the script was originally using $data_actors. I'm sure you're aware the database stores these as arrays where the first entry is nil, so compact helps to remove that anomaly.

Yes, you want to be using $game_actors when extracting actor data, but it is its own defined class (aptly named Game_Actors) instead of being an array that $data_actors is. As such, it does not have access to Array methods like size (or length, they do the same thing) and compact. While you could reimplement them, that's extremely overkill and, honestly, bad practice, especially when an alternate solution can be made.

The problem with $game_actors is that it initializes actors when it's requested by the game. If your game starts out with just one actor in the party, $game_actors is only aware of that one actor. Your window requires knowing how many total actors there actually are, so you will need to rely on $data_actors solely for the count.

Code:
class Window_Roster < Window_Selectable
  def initialize(x, y, width)
    super(x, y, width, Graphics.height - y - ($data_actors.compact.size * 29)
    self.index = 0
    activate
    refresh
  end

  def item
    index >= 0 ? $game_actors[index + 1] : nil
  end

  def item_max
    $data_actors.compact.size
  end

  def draw_item(index)
    item = $game_actors[index + 1]
    if item
      rect = item_rect_for_text(index)
      draw_text(rect, item.name)
    end
  end

  def refresh
    create_contents
    draw_all_items
  end
end
Not sure why the guide had data = [] under the initialize method as that was doing absolutely nothing (there's no data= method defined). I'm sure it was a typo and the @ is missing, but it's not necessary. We no longer need the instance variable
Code:
@data
anyways since we can just directly reference $game_actors for retrieving our actor data, thus the removal of make_item_list. We still use $data_actors to tell our window how many actors there are defined in the game.

As for the index + 1, that's because there's no such thing as $game_actors[0]. Indices start at 0, so we have to correlate index 0 as being $game_actors[1].

EDIT: Is there a way to not mention another user besides using CODE tags?
EDIT2: Forgot the index + 1
 
Last edited:

Pandappuccino

Depressed Panda
Member
Joined
Aug 2, 2020
Messages
6
Reaction score
18
First Language
English
Primarily Uses
RMVXA
Because the script was originally using $data_actors. I'm sure you're aware the database stores these as arrays where the first entry is nil, so compact helps to remove that anomaly.

Yes, you want to be using $game_actors when extracting actor data, but it is its own defined class (aptly named Game_Actors) instead of being an array that $data_actors is. As such, it does not have access to Array methods like size (or length, they do the same thing) and compact. While you could reimplement them, that's extremely overkill and, honestly, bad practice, especially when an alternate solution can be made.

The problem with $game_actors is that it initializes actors when it's requested by the game. If your game starts out with just one actor in the party, $game_actors is only aware of that one actor. Your window requires knowing how many total actors there actually are, so you will need to rely on $data_actors solely for the count.


Not sure why the guide had data = [] under the initialize method as that was doing absolutely nothing (there's no data= method defined). I'm sure it was a typo and the @ is missing, but it's not necessary. We no longer need the instance variable
Code:
@data
anyways since we can just directly reference $game_actors for retrieving our actor data, thus the removal of make_item_list. We still use $data_actors to tell our window how many actors there are defined in the game.

As for the index + 1, that's because there's no such thing as $game_actors[0]. Indices start at 0, so we have to correlate index 0 as being $game_actors[1].

EDIT: Is there a way to not mention another user besides using CODE tags?
EDIT2: Forgot the index + 1
That worked! Thanks a ton!
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
287
Reaction score
71
First Language
English
Primarily Uses
RMXP
Just for those curious readers I wish to add something here.

Code:
$data_actors.compact.size
is necessary because the first "actor" or index 0 is empty or nil by default. You'll never be able to edit it via the database.

compact method eliminates all nil values so the index 0 temporarily disappears.

Another way to get the same result would be...

Code:
$data_actors.size - 1
...because size method should be a number after all. Thanks to any of these methods we can retrieve the exact number of valid heroes found in the actors database. Of course those that have no name, well, won't be shown in the roster for the game won't do it on its own. You'd need to implement that by coding it yourself. :D
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Ami
--- Diary ---

M.Mage: It's the F.Mage's Diary. While she isn't here,i can read it.

May, 10: I'm hurt after the battle with the Minotaur. But luckily,F.Healer heal me with her Heal-2. That why,i Fall in Love with her.

M.Mage: Eh???
So... some of my Desktop hardware has kicked it apparently (still trying to figure out what and how at the moment :/ ) .... yay?
Stream will be live shortly with some Darkest Dungeon! Feel free to drop by!
Made a HUGE (YYOOOOJJ) Update to Monstructs and moving towards a Steam Early Access release!

Forum statistics

Threads
104,224
Messages
1,004,808
Members
135,740
Latest member
Animalblack
Top