add exists utility function

This commit is contained in:
Connor Olding 2018-06-10 16:35:28 +02:00
parent 771650613c
commit 47eb173dac
2 changed files with 16 additions and 2 deletions

View file

@ -96,6 +96,7 @@ local empty = util.empty
local lerp = util.lerp local lerp = util.lerp
local softchoice = util.softchoice local softchoice = util.softchoice
local unperturbed_rank = util.unperturbed_rank local unperturbed_rank = util.unperturbed_rank
local exists = util.exists
local game = require("smb") local game = require("smb")
game.overlay = cfg.enable_overlay game.overlay = cfg.enable_overlay
@ -446,8 +447,9 @@ local function init()
loadlevel(cfg.starting_world, cfg.starting_level) loadlevel(cfg.starting_world, cfg.starting_level)
end end
local res, err = pcall(network.load, network, cfg.params_fn) if exists(cfg.params_fn) then
if res == false then print(err) end network:load(cfg.params_fn)
end
if cfg.es == 'xnes' then if cfg.es == 'xnes' then
-- if you get an out of memory error, you can't use xNES. sorry! -- if you get an out of memory error, you can't use xNES. sorry!

View file

@ -5,6 +5,7 @@ local ipairs = ipairs
local log = math.log local log = math.log
local max = math.max local max = math.max
local min = math.min local min = math.min
local open = io.open
local pairs = pairs local pairs = pairs
local random = math.random local random = math.random
local select = select local select = select
@ -162,6 +163,16 @@ local function argsort(t, comp, out)
return out return out
end end
local function exists(fn)
local f = open(fn, "r")
if f then
f:close()
return true
else
return false
end
end
return { return {
signbyte=signbyte, signbyte=signbyte,
boolean_xor=boolean_xor, boolean_xor=boolean_xor,
@ -183,4 +194,5 @@ return {
rchoice2=rchoice2, rchoice2=rchoice2,
rbool=rbool, rbool=rbool,
argsort=argsort, argsort=argsort,
exists=exists,
} }