diff options
author | ubq323 <ubq323@ubq323.website> | 2023-01-14 21:06:16 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-01-14 21:06:16 +0000 |
commit | 0fe2f45a2fb33520f5ac86afef45f27c419b483b (patch) | |
tree | 361cdb1351298339727167116406fa407e61dd28 /shop2 | |
parent | 36e4a20adae28ea066dcc80ec14d8350bc62e31a (diff) |
shop2
Diffstat (limited to 'shop2')
-rw-r--r-- | shop2/main.lua | 11 |
1 files 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 |