Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can somebody help me understand this?

Asked by 8 years ago
function checkEven(number)
    local real_Number = tonumber(number)
    if real_Number then -- if can be a nuber then
        if (number%2) then
            return true
        else
            return false
        end
    end
end

see how he changed the value 'number' from a string into a number, how did he create the value called 'number' because I dont see how he did.

Also if by any change it has to do with him putting it in the parentheses how did he give it a number value???

0
simplified function: function even(n)n=tonumber(n)return n and n%2==0 end 1waffle1 2908 — 8y

1 answer

Log in to vote
1
Answered by
funyun 958 Moderation Voter
8 years ago
--"number" is a parameter of the function. If you call the function
--with a value to fill that parameter, then "number" will be that value.
--The two chunks of code below are equivalent.

function checkEven(number)
    local real_Number = tonumber(number)
    if real_Number then
        if number % 2 == 0 then
            return true
        else
            return false
        end
    end
end

print(checkEven(5))



number = 5

local real_Number = tonumber(number)
if real_Number then
    if number % 2 == 0 then
        print(true)
    else
        print(false)
    end
end
Ad

Answer this question