From 0fe2f45a2fb33520f5ac86afef45f27c419b483b Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 14 Jan 2023 21:06:16 +0000 Subject: shop2 --- shop2/main.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/shop2/main.lua b/shop2/main.lua index a79ab6f..8abe943 100644 --- a/shop2/main.lua +++ b/shop2/main.lua @@ -36,6 +36,14 @@ local function parsemeta(m) return out end +local function divisible(a,b) + -- returns whether a is divisible by b + -- because % doesn't work on nonintegers for some reason + if b == 0 then return false end + local x = a/b + return x == math.floor(x) +end + local function proctrans(tr) if tr.to ~= our_addr then return end if tr.type ~= "transfer" then return end @@ -63,8 +71,7 @@ local function proctrans(tr) return end - local remainder = tr.value % idesc.price - if remainder ~= 0 then + if not divisible(tr.value,idesc.price) then tell("i can only give you a whole number of items. make sure the amount you gave me is a multiple of "..idesc.price) refund() else -- cgit v1.2.3