RPG Maker Forums

Hi,

some month ago, I wanted to make a script, where you use different backgrounds for all scenes.

My first attempt was to write something like this:

module CONFIG SCENES = {Scene_Menu => "background1", Scene_Item => "background2"}endclass Scene_Menu alias create_background_old create_background def create_background if CONFIG::SCENES.include?(self.class) @background = Sprite.new @background.bitmap = Cache.menu(CONFIG::SCENES[self.class]) else create_background_old end endendclass Scene_Item alias create_background_old create_background def create_background if CONFIG::SCENES.include?(self.class) @background = Sprite.new @background.bitmap = Cache.menu(CONFIG::SCENES[self.class]) else create_background_old end endend#and so on
So like you see, it will be a bit difficult for a non-scripter, to add custom scenes without copy whole code parts and change scene_names.

I tried to solve this by iterate trough SCENE and apply changes only to the scenes included in the constant, but I failed, cause I didnt know how to do this.

Now, some month later, I have learned something about meta-programming.

This is how i could write it now:

module CONFIG SCENES = {Scene_Menu => "bg1", Scene_Item => "bg2"} #and so onendSCENE.each_key do | scene | next unless scene.ancestors.include? Scene_MenuBase scene.class_eval do def create_background @background_sprite = Sprite.new @background_sprite.bitmap = Cache.menu(CONFIG::SCENES[class.self]) end endend
My question now is, if it is ok to write code like that above or stick with the old code?

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,018
Messages
1,018,357
Members
137,803
Latest member
andrewcole
Top