RPG Maker Forums

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?

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,049
Messages
1,018,547
Members
137,835
Latest member
yetisteven
Top