So after going through some tutorials on Ruby scripting for RPG Maker Ace, I wrote a ruby script to play music when the menu is selected. However I ran into a few issues. Here is my code so far:
#Menu Music Scriptclass Scene_Map < Scene_Base alias bg_menumusic_call_menu call_menu def call_menu $last_bgm = RPG::BGM.last $last_bgs = RPG::BGS.last RPG::BGM.new("Town5", 100, 125).play bg_menumusic_call_menu endendclass Scene_Menu < Scene_MenuBase alias bg_menumusic_menu_terminate terminate def terminate if SceneManager.scene_is?(Scene_Map) $last_bgm.replay rescue nil $last_bgs.replay rescue nil end bg_menumusic_menu_terminate endendThe problem I run into is this: If I don't use $ for global, the code in Scene_Menu < Scene_Menu_Base does not know the variables exist for the sound that played before the menu was called, so it is nil every time. However, if I use globals, well, I can run into obvious problems later.
So far the global solution is working for my project, but I'd like to get around it to avoid possible later issues. Suggestions on how to make this work without using globals? I assume I need to store the variables somewhere else, but is there such a place that both classes can access?