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
31,355
Reaction score
7,668
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
564
Reaction score
275
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
564
Reaction score
275
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

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,977
Members
137,563
Latest member
cexojow
Top