diff --git a/main.lua b/main.lua index ba79f7d..b3be9c3 100644 --- a/main.lua +++ b/main.lua @@ -96,6 +96,7 @@ local empty = util.empty local lerp = util.lerp local softchoice = util.softchoice local unperturbed_rank = util.unperturbed_rank +local exists = util.exists local game = require("smb") game.overlay = cfg.enable_overlay @@ -446,8 +447,9 @@ local function init() loadlevel(cfg.starting_world, cfg.starting_level) end - local res, err = pcall(network.load, network, cfg.params_fn) - if res == false then print(err) end + if exists(cfg.params_fn) then + network:load(cfg.params_fn) + end if cfg.es == 'xnes' then -- if you get an out of memory error, you can't use xNES. sorry! diff --git a/util.lua b/util.lua index a127fe3..3998453 100644 --- a/util.lua +++ b/util.lua @@ -5,6 +5,7 @@ local ipairs = ipairs local log = math.log local max = math.max local min = math.min +local open = io.open local pairs = pairs local random = math.random local select = select @@ -162,6 +163,16 @@ local function argsort(t, comp, out) return out end +local function exists(fn) + local f = open(fn, "r") + if f then + f:close() + return true + else + return false + end +end + return { signbyte=signbyte, boolean_xor=boolean_xor, @@ -183,4 +194,5 @@ return { rchoice2=rchoice2, rbool=rbool, argsort=argsort, + exists=exists, }