Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can somebody help me understand this?

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???

2 comments

0

simplified function: function even(n)n=tonumber(n)return n and n%2==0 end

1 answer

--"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

This discussion is preserved as it was. New answers, comments, and votes are closed.