Variable or swithces? Best practice advice focused on performance.

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,077
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
So, let's assume I wanna make a system that will decide something, according to some things that occur.

Let's say we got 11 Events.

There might be 3 things possibly happening to each of them. 

What happens to the first, will determine what happens on the second. What happens on both first and second will determine the third and so on till let's say 11.

A lot of complex calculations is going on. 

Since it is three things that can happen, I can have either 11 variables with conditional branches for value 1, 2, else.

On the other hand, I can use 33 switches to determine what will happen.

Consider spaghetti code not significant.

Consider 33 switch hardship and complexity not significant.

What will be the best approach to make this, to retain as much performance as possible?

33 Switches or 11 variables?
 
Last edited by a moderator:

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,529
Reaction score
3,680
First Language
Java's Crypt
Primarily Uses
RMMZ
The smaller code will be the faster one.
 

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,077
Reaction score
2,654
First Language
Greek
Primarily Uses
RMMZ
Variables then. :) Thanks.
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,000
First Language
Tagalog
Primarily Uses
RMVXA
If they happen in a fixed order of succession, you might even be able to use a single variable..
 

Zeriab

Huggins!
Veteran
Joined
Mar 20, 2012
Messages
1,266
Reaction score
1,409
First Language
English
Primarily Uses
RMXP
Don't worry about performance decrease on storing switches and variables. Unless you are using millions you won't see any difference, and even then millions might work just fine.

What matters is the event code. How many event commands must be processed.

My suggestion is to go for the simplest solution first.

Could be easily fast enough. You can show use what you end up with. Makes it much easier for us to give you hints.

*hugs*

 - Zeriab
 

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

Latest Threads

Latest Profile Posts

Is there anyone need help with anything except art and music?
is Gotcha Gotcha Games Inc. = KADOKAWA CORPORATION? I haven't found this topic yet, Want to know for credits on my game. Thanks.
If you get everything you want, when you want it, it kills your creativity. If you never get anything you want, you're forced to be creative with what you have.
Old chiptune loops free for use.
I think I've got my hero designs pretty much finialised ( still got some tweaks. ) In the end it'll be the four outfit colour variants with four different skintones.

Forum statistics

Threads
104,299
Messages
1,005,378
Members
135,818
Latest member
Hennet91
Top