aboutsummaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2016-06-25 15:39:52 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2016-06-25 15:39:52 +0200
commitb4317fceb6dadf7973acb1bbebfb1b970bdbe7a0 (patch)
tree00253c84bd5b2b0fed0a5a0db18c63e202dd5305 /init.lua
parentb86e76632c0727204f974e2847f1ea8457414db1 (diff)
downloadatm-b4317fceb6dadf7973acb1bbebfb1b970bdbe7a0.tar.gz
atm-b4317fceb6dadf7973acb1bbebfb1b970bdbe7a0.tar.bz2
atm-b4317fceb6dadf7973acb1bbebfb1b970bdbe7a0.zip
Works now
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua25
1 files changed, 9 insertions, 16 deletions
diff --git a/init.lua b/init.lua
index 52ca563..bc1970d 100644
--- a/init.lua
+++ b/init.lua
@@ -1,7 +1,6 @@
atm = {}
atm.balance = {}
atm.pth = minetest.get_worldpath().."/atm_accounts"
-atm.linecount = 0
function atm.showform (player)
atm.readaccounts()
@@ -33,23 +32,21 @@ function atm.showform (player)
end
-function atm.readaccounts ()
+function atm.readaccounts ()
+ local b = atm.balance
local file = io.open(atm.pth, "r")
- local l = 0
if file then
repeat
- l = l + 1
local balance = file:read("*n")
- if x == nil then
+ if balance == nil then
break
end
local name = file:read("*l")
- atm.balance[name:sub(2)] = balance
+ b[name:sub(2)] = balance
until file:read(0) == nil
io.close(file)
- atm.linecount = l
else
- atm.balance = {}
+ b = {}
end
end
@@ -58,18 +55,14 @@ function atm.saveaccounts()
return
end
local data = {}
-
- local l = 0
for k, v in pairs(atm.balance) do
table.insert(data, string.format("%d %s\n", v, k))
- l = l+1
- end
- if not (l < atm.linecount) then
- local output = io.open(atm.pth, "w")
- output:write(table.concat(data))
- io.close(output)
end
+ local output = io.open(atm.pth, "w")
+ output:write(table.concat(data))
+ io.close(output)
+
end
minetest.register_on_joinplayer(function(player)