• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Check number value

president vankk

Web Developer & AuraOT Owner
Joined
Jul 10, 2009
Messages
5,719
Solutions
9
Reaction score
339
Hi my dear friends,

How I can check if the number is multiple of 3 and integer on lua? The part of multiple I did check below, but I'm facing some problems with the integer part.

Code:
if tonumber(msg) and npcHandler.topic[cid] == 1 then
    local n = tonumber(msg)      
    if (n % 3 == 1) then
        npcHandler:say("This number is not multiple of three.", cid)
        npcHandler.topic[cid] = 0
        return true
    end
end

Thanks.
 
Hi my dear friends,

How I can check if the number is multiple of 3 and integer on lua? The part of multiple I did check below, but I'm facing some problems with the integer part.

Code:
if tonumber(msg) and npcHandler.topic[cid] == 1 then
    local n = tonumber(msg)   
    if (n % 3 == 1) then
        npcHandler:say("This number is not multiple of three.", cid)
        npcHandler.topic[cid] = 0
        return true
    end
end

Thanks.
n % 3 == 0
Code:
In computing, the modulo operation finds the remainder after division of one number by another 
(sometimes called modulus). Given two positive numbers, a (the dividend) and n (the divisor), a
 modulo n (abbreviated as a mod n) is the remainder of the Euclidean division of a by n.
 
n % 3 == 0
Code:
In computing, the modulo operation finds the remainder after division of one number by another
(sometimes called modulus). Given two positive numbers, a (the dividend) and n (the divisor), a
modulo n (abbreviated as a mod n) is the remainder of the Euclidean division of a by n.


If I say 5 to the NPC then will returns it: Are you sure that you want exchange 5 silver medals for 1.6666666666667 golden medal?
If I say 4 to the NPC then will returns it: are you sure that you want exchange 4 silver medals for 1.3333333333333 golden medal?
 
If I say 5 to the NPC then will returns it: Are you sure that you want exchange 5 silver medals for 1.6666666666667 golden medal?
If I say 4 to the NPC then will returns it: are you sure that you want exchange 4 silver medals for 1.3333333333333 golden medal?
Your question was, "multiple of 3 and integer on lua" and i resolved the issue, you did not like my post, so no more help for you.
 
That is because you don't understand the n % 3 == 0 formula.
if n % 3 == 0 then
Any number which you divide by 3 with a remainder of 0 is divisible by 3.

Oh sorry, it was by bad, I says using / 3 on the message sended by the NPC. It works perfectly! Thanks.
 
Back
Top