Simplifying instances of scenes

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
I have a function that has conditional operator inside of Game_System that checks if the scene I am in currently is at Scene_Menu or Scene_Map. However, it is very natural that this code:

if(SceneManager._scene instanceof Scene_Map || SceneManager._scene instanceof Scene_Menu) {}becomes impractical if I am about to check Scene_Item, Scene_Equip, Scene_Status, Scene_Save, Scene_Load and Scene_End. It would become long and adding the || everytime makes it even pedestrian when coded. Is there a way to simplify this?
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
You could make a separate function that will return true or false, like so:

function isSceneClass(scene, klasses) { for(var i = 0; i < klasses.length; i++) { if(scene instanceof window[klasses]) { return true; } } return false;}Make sure that klasses is an array, though, and it contains strings that are the same as the scene names.
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
- edit - 

It finally works. Thanks Zale, I added it on SceneManager instead :)
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD

Forum statistics

Threads
105,868
Messages
1,017,078
Members
137,580
Latest member
Snavi
Top