Hello everyone! Happy new year! I have been writing my code like this for a while when needed and I have hated it. I am quite the clean freak and I feel like there is a great way to downsize but I cant find it anywhere. Here is the code:
if KitRarity == "Basic" then
RequiredDiamonds = 10000
WaitTime = 900
elseif KitRarity == "Rare" then
RequiredDiamonds = 20000
WaitTime = 3600
elseif KitRarity == "Epic" then
RequiredDiamonds = 50000
WaitTime = 14400
elseif KitRarity == "Legendary" then
RequiredDiamonds = 1000000
WaitTime = 43200
elseif KitRarity == "Ancient" then
RequiredDiamonds = 500000
WaitTime = 86400
elseif KitRarity == "Exotic" then
RequiredDiamonds = 1000000
WaitTime = 259200
end
Pretty much as clean as you can get, tables and stuff wont really save you from much size. If you don’t like this code you can make value instances and read them.
Glad you like it. As far as actual downsizing goes, it isn’t really visible in an individual use case. All the information has to be available one way or another, but we strive for approaches a principled programmer would use, such as DRY (don’t repeat yourself).
It’s completely fine if you use if-else statements for short options, like if, ifelse, and else, but they can get too repetitive and even unreadable. In scenarios like this where constant data is used, it’s usually a good idea to form a table and reuse this table everywhere. It can be it’s own module. Then any changes to this module apply to any code reading from it. It can be placed into a replicated server and used both by the server and clients.
Lastly, in terms of consumed memory, if-else statements should occupy a bit less space, but the numbers and benefits turn if the module is used in a lot of different places. Not that the used memory is a significant factor here in any way.
We just try to write code that is balanced between great performance and readability, and maintainability.