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

Discussion in 'RGSSx Script Support' started by dsod, Apr 8, 2017.

  1. dsod

    dsod Warper Member

    Messages:
    3
    Likes Received:
    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.
     
    #1
  2. Andar

    Andar Veteran Veteran

    Messages:
    28,141
    Likes Received:
    6,372
    Location:
    Germany
    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.
     
    #2
    dsod likes this.
  3. dsod

    dsod Warper Member

    Messages:
    3
    Likes Received:
    0
    First Language:
    english
    Primarily Uses:
    RMVXA
    Thank you so much! been stuck on this for a while never would have thought it was that simple xD
     
    #3
  4. Another Fen

    Another Fen Veteran Veteran

    Messages:
    519
    Likes Received:
    234
    First Language:
    German
    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...
     
    #4
  5. dsod

    dsod Warper Member

    Messages:
    3
    Likes Received:
    0
    First Language:
    english
    Primarily Uses:
    RMVXA
    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.
     
    #5
  6. Another Fen

    Another Fen Veteran Veteran

    Messages:
    519
    Likes Received:
    234
    First Language:
    German
    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. :)
     
    #6

Share This Page