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 » Game Design
Home Search
 

Re: Getting certain digits out of a numbervalue?

Previous Thread :: Next Thread 
Robloxmannnnnnnn is not online. Robloxmannnnnnnn
Joined: 21 Feb 2009
Total Posts: 789
27 May 2015 05:00 PM
I doubt this is possible, but is it possible to this:

Let's say NValue is 12345.

I want a script to check if the second digit of NValue is 2, but not check the 1, 3, 4 or 5.
Report Abuse
morash is not online. morash
Joined: 22 May 2010
Total Posts: 5834
27 May 2015 05:09 PM
function checkDigit(val, x)
math.floor(val/(10^(x-1))) % 10
end
Report Abuse
Robloxmannnnnnnn is not online. Robloxmannnnnnnn
Joined: 21 Feb 2009
Total Posts: 789
27 May 2015 05:09 PM
Can you explain what each line does so I can modify it to my liking?
Report Abuse
Qorm is not online. Qorm
Joined: 25 Jul 2010
Total Posts: 1650
27 May 2015 05:11 PM
NValue="12345"
x=(string.sub(NValue,2,2))
if x=="2" then
print"NValue is 2"
end

probably not the most efficient way but it works
Report Abuse
Qorm is not online. Qorm
Joined: 25 Jul 2010
Total Posts: 1650
27 May 2015 05:12 PM
wait i didnt read the question right, forget about what i said above
Report Abuse
Robloxmannnnnnnn is not online. Robloxmannnnnnnn
Joined: 21 Feb 2009
Total Posts: 789
27 May 2015 09:35 PM
bump
Report Abuse
Fortixs is not online. Fortixs
Joined: 15 Dec 2008
Total Posts: 3967
27 May 2015 10:19 PM
What you can do is make an array (a table) that holds each of the digits in NValue. Then you can check if the second index is equal to 2.
Report Abuse
Fortixs is not online. Fortixs
Joined: 15 Dec 2008
Total Posts: 3967
27 May 2015 10:23 PM
--setup array
local array = {0, 0, 0, 0, 0}

--go through the length of NValue (the number of digits in NValue) and assign each to an array index.
for i = 1, #NValue do

array[i] = tonumber(string.sub(NValue, i, i + 1))

end

--then check if the second digit is 2
if array[2] == 2 then
--do whatever
else
--do whatever else
end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Game Design
   
 
   
  • 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