- Home /
Does long script matters
I have script with tons of if statement. I think that is is going to be over 3000 lines. Does it matter for mobile (Andriod)?
Why tons of if statements? Can't you optimize your code with switch statements or some good logic? Because tons of if statements is sure an overkill for processing.
Answer by DMGregory · Jun 06, 2014 at 02:57 PM
Often in software development, including gamedev, the question "can my platform handle it?" is strictly secondary to the question "can my dev team handle it?"
If there's one tiny glitch in those 3000 lines, how many days of your team's productivity will you lose hunting it down? How many of those glitches will you ship, because you never found them?
Keeping scripts clean & concise is good for development productivity, as well as performance.
Consider whether you can use some software design patterns (particularly game-specific ones) to make this code simpler, or split it into several files that each have a smaller, more focused role & responsibility.
For instance, if many of your "if" statements deal with different states your game/character can be in, consider having separate scripts for each state, and a manager that turns just the appropriate one on as needed. This keeps bugs more localized - it will usually be either a bug in just one state, or a bug in state selection, but you're less likely to have bugs from one state spilling over to affect others.