I need advice on one of my scripts. I'm pretty new to scripting, and I'm trying to make an options screen that allows the player to adjust the volume of the background music. I wrote this script to adjust the volume of the game by an amount defined by the "vol_adjust" variable. It seems to work fine at adjusting the volume. What I'm having trouble with is figuring out how to call the script to adjust the volume whenever a new BGM plays.
What I'm currently doing is running a parallel process common event with
*note right now I'm just setting the vol_adjust value to 0.5 to test the script I'll reset this to something the player defines later using the options screen.
I'm worried that my script is really inefficient, and I don't like having to use the parallel process common event. I was wondering if there was a seasoned scripter who could give me any advice that could help me improve my work?
My BGM Adjust Script
What I'm currently doing is running a parallel process common event with
Code:
bgmchange = Bgm_Adjust.new
bgmchange.vsetting(0.5)
I'm worried that my script is really inefficient, and I don't like having to use the parallel process common event. I was wondering if there was a seasoned scripter who could give me any advice that could help me improve my work?
My BGM Adjust Script
Code:
# BGMVolume Adjust Script
# Adjusts BGM volume according to the value of vol_adjust
class Bgm_Adjust
#iniitialize the class
def initialize
if vol_adjust = nil
vol_adjust = 1
end
end
# This method gets information about the current BGM being played
def vsetting(vol_adjust)
bgm_playing = RPG::BGM.last
current_bgm_n = bgm_playing.name
current_bgm_v = 100
current_bgm_p = 100
if current_bgm_n != ""
current_bgm_p = bgm_playing.pitch
current_bgm_v = bgm_playing.volume
end
#This line resets the volume by the vol_adjust value (should be from 0-1)
current_bgm_v = vol_adjust * current_bgm_v
#This line plays the BGM with the adjusted volume
if current_bgm_n != ""
Audio.bgm_play("Audio/BGM/" + current_bgm_n.to_s, current_bgm_v, bgm_playing.pitch)
end
end
end