generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: More efficient code

Previous Thread :: Next Thread 
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
03 Aug 2013 08:09 AM
Ok, so I have this code that uses string.rep and math.floor 4 times and string.gsub 9 times and I was wondering how I can make it more efficient (It wont be commonly used by the same ideas may apply to more complex code that is used more commonly)

Take a look at it, use it if you wish:

local getRomanNumeral = function(number)
return (('M'):rep(math.floor(number/1000)) .. ('C'):rep(math.floor((number%1000)/100)) .. ('X'):rep(math.floor((number%100)/10)) ..
('I'):rep(math.floor((number%10)/1))):gsub('CCCCC', 'D'):gsub('DCCCC', 'CM'):gsub('CCCC', 'CD'):gsub('XXXXX', 'L'):gsub('LXXXX', 'XC'):gsub('XXXX', 'XL')
:gsub('IIIII', 'V'):gsub('VIIII', 'IX'):gsub('IIII', 'IV')
end
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
03 Aug 2013 08:21 AM
When you say efficient, do you mean speed or readability?
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
03 Aug 2013 08:23 AM
Speed. Its currently very reliable (Up to 5000, but I doubt anyone will get to round 5000 in my game)
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
03 Aug 2013 08:24 AM
I would design different methods to do the same thing and compare their running times.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
03 Aug 2013 08:27 AM
Well in order to do that I need to know more.

Could I combine multiple parts of that with gsub? I don't like having to use it 9 times (Maybe if I could use it only 3 it would be better)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image