0

So I zipped my Love2D project and it works when I launch it in the same folder, but elsewhere my io.open doesn't work. Here's my file system:

...
utils
   |json.lua  <-- library I use for encoding and decoding
   |JSONHandler.lua
   |parameters.json
conf.lua
main.lua
...

I get my error in JSONHandler.lua where I have:

local json = require "utils/json"

Handler = {
   filename = "utils/parameters.json",
   params = {},
   ...
}

function Handler:init()
   local o = {}
   setmetatable(o, self)
   self.__index = self

   local file = io.open(self.filename, "r")
   local content = file:read("a")
   ...

My file ends up being nil

I tried many different relative paths for filename but nothing worked so I'm wondering how .love files handle paths, how should I track to my parameters.json?

2
  • 2
    Maybe try love.filesystem? Or you could use parameters.lua and a table for config instead. Commented Sep 28, 2023 at 1:39
  • Is parameters.json inside the zip archive? Commented Sep 28, 2023 at 2:49

1 Answer 1

1

It probably works when you do not move the .love file because it still has access to the original files from the working directory.

Lua can not read content in zip files out of the box, but Love2d offers love.filesystem.

It also has file wrappers, but if you just want to read the content prefer read:

local content = love.filesystem.read(self.filename)

Note that you can only read files in the love zip, in the working directory and in the save directory.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.