Hi there,
I'm brand new to this (as it went on sale in Steam), and I was looking at using SephTrick Wannabe!'s scripting code he posted here for using Regions to play different BGMs. So far I've been able to weed out small scripting errors, but I'm having a new issue and cannot get past it.
Here's what I have so far:
Also note that I'm too stupid to add a "Spoiler" option, I apologize.
#==============================================================================
# ** Meph's Simple Region Audio (Requested by Cecillia)
#------------------------------------------------------------------------------
# MephistoX
# Version 1.0
# 28/04/2012
# RPGMaker VXAce
#------------------------------------------------------------------------------
# * Version History :
#
# Version 1 ---------------------------------------------------- (26/04/2012)
# - First Released Version
#------------------------------------------------------------------------------
# * Description :
#
# This Script allow the user to configure different BGMs depending on the
# region where the player is, if no bgm defined for that region the BGM
# will stay, also works with autoplay.
#------------------------------------------------------------------------------
# * Instructions :
#
# Place The Script in the Materiales Section of your Script List
# See The Module to Check the Audio Configuration for the Map.
#------------------------------------------------------------------------------
# * Credits
#
# Avaliable for Any Proyect.
#==============================================================================
#==============================================================================
# ** Region Audio
#==============================================================================
module Region_Audio
#--------------------------------------------------------------------------
# * BGM Config : Configure the BGM for Each Map and Region
# - BGM_Config = {Map_ID => {Region_ID => 'BGM Name'}}
#--------------------------------------------------------------------------
BGM_Config = {}
BGM_Config[001] = {1 => '24', 2 => '24', 3 => '24',
4 => '35', 5 => '24', 6 => '45', 7 => '97', 63 => '24'}
#BGM_Config[1] = {1 => 'Field1', 2 => 'Field2', 3 => 'Field3'}
#--------------------------------------------------------------------------
# * Defined Audio? : Check if Audio for Map and Region is Defined
#--------------------------------------------------------------------------
def defined_audio?(map_id, region_id)
# Return true if Map_ID defined and Region_ID defined
return (BGM_Config.key?(map_id) && BGM_Config[map_id].key?(region_id))
end
end
#==============================================================================
# ** Game_Map
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# * Mixin Region_Audio
#--------------------------------------------------------------------------
include Region_Audio
#--------------------------------------------------------------------------
# * Alias Listing
#--------------------------------------------------------------------------
alias_method :meph_chgrgbgm_gmap_autoplay, :autoplay
#--------------------------------------------------------------------------
# * Automatically Switch BGM and BGS
#--------------------------------------------------------------------------
def autoplay
# Check if Map ID is a Configured Region Music Map
if defined_audio?(@map_id, $game_player.region_id)
# Get BGM Name based on Map_ID and region where the player is
bgm_name = BGM_Config[@map_id][$game_player.region_id]
# Play the gotten BGM
return Audio.bgm_play('Audio/BGM/' + bgm_name, 100, 100)
end
# The Usual
meph_chgrgbgm_gmap_autoplay
end
#--------------------------------------------------------------------------
# * Update Region Audio : Update the Audio based on Region ID
#--------------------------------------------------------------------------
def update_region_audio(r_id)
# Get BGM
bgm_name = BGM_Config[@map_id][r_id] ((Problem is on this line, 85))
# Return if Not Defined Audio or Currently Playing defined BGM
return if !defined_audio?(@map_id, r_id) || (@map.bgm.name == bgm_name)
# Play BGM
Audio.bgm_play('Audio/BGM/' + bgm_name, 100, 100)
end
end
#==============================================================================
# ** Game_Player
#==============================================================================
class Game_Player
#--------------------------------------------------------------------------
# * Alias Listing
#--------------------------------------------------------------------------
alias_method :meph_chgrgbgm_gplay_init , :initialize
alias_method :meph_chgrgbgm_gplay_update, :update
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# The Usual
meph_chgrgbgm_gplay_init
# Region ID
@region_id = 0
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
meph_chgrgbgm_gplay_update
# If Actual Region is different from saved Region
if region_id != @region_id
# Save Actual Region
@region_id = region_id
# Update Map Region Audio
$game_map.update_region_audio(@region_id)
end
end
end
The issue is coming up in line 85: "Script 'Region BGM Config' (what I named it) line 85: NoMethodError occured. Undefined method '[]' for nil:nilClass."
Before this I had all (so far) of my regions all painted out and they were all working properly, switching properly, with no issues. The issue appeared after I added events to switch to new maps, Specifically, while on/or after entering my first town from the world map. I painted all of the tiles with a region, just in case that was causing the issue, but it seems unchanged. I wanted to leave all towns/dungeons separate of regions, if possible, as to not waste region space. I want to save that (again only if possible) for the world map or other special areas if I deem it necessary. Thank you in advance for your help!
No Method Error VX Ace
● ARCHIVED · READ-ONLY
-
-
UPDATE:
It seems that I'm only having this issue specifically while entering my town, regardless of whether there is music to play from script or from the map properties or a complete lack of music period. As I enter the town from the world map, the error pops and exits the game. Also to note, I do have a tent/building that uses the same type of entering/exiting transfer event as from the world map to the town. I don't know if this helps or not, but I figure more information is better than being too vague?
Thanks again.
Edit:
If I start inside the town, paint the region in the town, as I start the game I receive the error as well.
Edit 2:
I think I figured it out. It *seems* I was receiving the error due to not having a new map listed in the directory, "BGM_Config = {}". I'll edit this again when I smooth things out. -
Ruske, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.
To add a spoiler, do this:
Code:And when adding code, also use code tags (the same way - just replace the word spoiler with the word code) - this keeps the formatting nice and makes it easier to read.[spoiler]spoiler'd stuff[/spoiler]