Forgive me if this is obvious, I checked out the tutorial on the LUA
maths library because that's where I expected to find it...
One of my basic compilers provide a maths operation for selecting any
digit of a variable, say digit 2 of 255, and setting another variable to that value.
The syntax would be:
variable1 = variable2 DIG 2
Is there any feature like that in LUAplayer that doesn't use exsessive time?
Cheers, Art.
'DIG' equivalent in LUAplayer?
Moderators: Shine, Insert_witty_name
Re: 'DIG' equivalent in LUAplayer?
Math is a good start, but there are many ways to implement it, e.g.:Art wrote:Forgive me if this is obvious, I checked out the tutorial on the LUA
maths library because that's where I expected to find it...
Code: Select all
function dig(number, digit)
local digitValue = math.pow(10, digit)
return math.floor(math.mod(number, digitValue) / (digitValue / 10))
end
function dig(number, digit)
local numberString = tostring(number)
local index = string.len(numberString) - digit + 1
return tonumber(string.sub(numberString, index, index))
end
assert(dig(7654, 1) == 4)
assert(dig(7654, 2) == 5)
assert(dig(7654, 3) == 6)
assert(dig(7654, 4) == 7)
That's great thanx :)
I'll take the top one because it looks the most like on paper..and it looks shorter too.
102/10 = 10.2 <-- DIG 0 = 2
10/10 = 1.0 <-- DIG 1 = 0
1/10 = 0.1 <-- DIG 2 = 1
I have figured out the syntax to reverse:
var1 = dig(var4, 3)
var2 = dig(var4, 2)
var3 = dig(var4, 1)
Cheers, Art.
I'll take the top one because it looks the most like on paper..and it looks shorter too.
102/10 = 10.2 <-- DIG 0 = 2
10/10 = 1.0 <-- DIG 1 = 0
1/10 = 0.1 <-- DIG 2 = 1
I have figured out the syntax to reverse:
var1 = dig(var4, 3)
var2 = dig(var4, 2)
var3 = dig(var4, 1)
Cheers, Art.