undefined method for 'name' for [1]:Array

dsod

Warper
Member
Joined
Apr 7, 2017
Messages
3
Reaction score
0
First Language
english
Primarily Uses
RMVXA
Hey im a real noob at the min but im trying to make the currency used in the game to be set to the name of a character/actor so the user can call it what they want.
I have this:
$data_system.currency_unit = $game_actors
[1].name

But it gives me this error:
Script 'Game_Interpreter' line 1411:NoMethodError occured.
undefined method for 'name' for [1]:Array

Im unsure on how my script this small can be causing this much of an issue xD If anybody has an idea on what im doing wrong please help.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
30,037
Reaction score
7,031
First Language
German
Primarily Uses
RMMV
that is because the [1].name is in the next line, not in the same line as the $game_actors

You need a manual break that tells the engine to look in the next line for the completion of the command, and you do that by manually pressing enter after the opening bracket.

$data_system.currency_unit = $game_actors[
1].name

will work where your variant creates an error.
 

dsod

Warper
Member
Joined
Apr 7, 2017
Messages
3
Reaction score
0
First Language
english
Primarily Uses
RMVXA
that is because the [1].name is in the next line, not in the same line as the $game_actors

You need a manual break that tells the engine to look in the next line for the completion of the command, and you do that by manually pressing enter after the opening bracket.

$data_system.currency_unit = $game_actors[
1].name

will work where your variant creates an error.
Thank you so much! been stuck on this for a while never would have thought it was that simple xD
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
559
Reaction score
272
First Language
German
Primarily Uses
Even though this isn't related to your question, keep in mind that by default the $data_... variables are only initialized when starting the game (or after resetting the game by pressing F12).
As a result all changes will be preserved when you load another savestate or start a new game, and all changes are reset to editor settings whenever the player quits the game.

In order to change the currency unit to an actors name, I'd suggest to redefine Vocab.currency_unit instead:
Code:
module Vocab
  def self.currency_unit
    return $game_actors[1].name
  end
end
In general, if you want to modify the database settings for your savestate, you could also modify these methods from the DataManager module to correct the settings whenever the player saves/loads a savestate or starts a new game:
create_game_objects is used for a new game
make_save_contents is used to determine what data is saved in your savefiles
extract_save_contents is used to restore the games state from savefile data

Hope this helps anyway...
 

dsod

Warper
Member
Joined
Apr 7, 2017
Messages
3
Reaction score
0
First Language
english
Primarily Uses
RMVXA
Even though this isn't related to your question, keep in mind that by default the $data_... variables are only initialized when starting the game (or after resetting the game by pressing F12).
As a result all changes will be preserved when you load another savestate or start a new game, and all changes are reset to editor settings whenever the player quits the game.

In order to change the currency unit to an actors name, I'd suggest to redefine Vocab.currency_unit instead:
Code:
module Vocab
  def self.currency_unit
    return $game_actors[1].name
  end
end
In general, if you want to modify the database settings for your savestate, you could also modify these methods from the DataManager module to correct the settings whenever the player saves/loads a savestate or starts a new game:
create_game_objects is used for a new game
make_save_contents is used to determine what data is saved in your savefiles
extract_save_contents is used to restore the games state from savefile data

Hope this helps anyway...
Oh right thanks I thought that may have been the case, so does that script set the currency only for the state you are currently on? Again sorry noob here.
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
559
Reaction score
272
First Language
German
Primarily Uses
The script does not change $data_system.currency_unit . Instead, it changes the source the currency unit is read from by the rest of the scripts.

By default, the name of the currency value is read by calling Vocab.currency_unit, which in turn returns the currency name you specified in the database (you can find the original implementation of this method in the Vocab script at the top of your script list, in line 109-111).
The script above redefines this method: If a method is defined multiple times (same name for the same class/module), the version closer to the Main script takes precedence (this is why you usually put scripts under the Materials section right before the Main script).

This script changes the method so it always returns Actor#1's name, regardless the value of $data_system.currency_unit , so you don't have to change that variable (you can change the source of your currency unit within the script if necessary).

Hope that solution is okay. :)
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Quick question, what's the best way to capture-er, I mean RECRUIT playtesters? Should I make a project thread and use that?
Node Graph out of Date. Rebuilding...
Does anyone know of any good Discord groups for art or biology discussion, that sort of thing?
Trying to access kissanime, Facing issues, Here are 5 working KissAnime Alternatives.
I ready asked for bump rules, but I forget to ask how much bumping you can use per thread? How bumping can I post per thread? Thank you.

Forum statistics

Threads
98,054
Messages
948,927
Members
129,332
Latest member
SoulDiamond
Top