Jump to content

Lua invalid filepath


Recommended Posts

I want to read

Don't Starve Together\data\scripts\mainfunctions.lua

with the following code:

local path_mainfunctions_nix = "../../data/scripts/mainfunctions.lua"
local path_mainfunctions_win = "..\\..\\data\\scripts\\mainfunctions.lua"

local path_mainfunctions = nil
if strfind(GLOBAL.PLATFORM, "win") then
	path_mainfunctions = path_mainfunctions_win
elseif strfind(GLOBAL.PLATFORM, "nix") or strfind(GLOBAL.PLATFORM, "mac") then
	path_mainfunctions = path_mainfunctions_nix
else
	print("[Debugger] Your platform is not supported!")
	return -1
end

file_mainfunctions = io.open(path_mainfunctions)

However the game crashes and outputs the following error:

[00:01:32]: [string "../mods/test/modmain.lua"]:31: invalid filepath

well, 31st line is the "io.open" invocation...

maybe Klei's Lua interpreter implementation has something to do with it?

Link to comment
Share on other sites

@Nymphoenix, welcome to the forums.

Try

local path_mainfunctions = "scripts/mainfunctions.lua"
file_mainfunctions = io.open(path_mainfunctions)

(even on my Windows it required forward slashes and rejected backslashes).

I hope you'll make sure your code is added only if it's needed (i.e. it hasn't been already added), won't crash if the user doesn't have permission to write to it and put instructions how to revert the changes/fix their DST installation on the mod's page.

Edited by Muche
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...