About Calling Doubles Together

Hi, I am learning about idle/incremental games and for making my code shorter I need to store my doubles in a group?? or array?

for example I have doubles like “clickValue, clickUpgradeCost …” I want to call them all together like “MyDoubles”.

I want to put “Mydoubles” in this code to shorten things.

Idle Clicker Kit | Game Toolkits | Unity Asset Store [FREE]

Even if you don’t use it I think you might get some value from looking at the code.

Cheers,
John A

Shorter didn’t mean better. Make sure you can understand what is going on inside. Preferably by just glancing through.

Working with arrays is nice and very extensible. But may be confusing, if you are not just to work with.

Look up “arrays” in C# to find the basic syntax for what you’re thinking about.

However, as @Antypodish points out, that will not necessarily make your code better or faster. It will make it harder to read for no performance benefit. (Actually… it makes the computer do more work.)

Right now your variables each have nice, human readable names. When you do some math, it’ll look like:

If you instead put every number in an array the same equation would look like:

By all means learn about arrays. But keep in mind that they generally only improve your code when you have a collection of related things that you will use together, in a loop or something like that.


Also, fur future reference, the Scripting section is the right place for these questions.

Thank you guys for answers :slight_smile:

1 Like