|
| 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
|
  |
| 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 |
|
|
|
| 27 May 2015 05:09 PM |
| Can you explain what each line does so I can modify it to my liking? |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
| |
|
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
|
  |
| 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 |
|
|