I have a finished game called snaketime. It's nothing special. It works when I run it on my Macbook from the command line using this:
Code: Select all
love .
This is the error:
Code: Select all
Error
main.lua:91: attempt to index local 'ldtkFile' (a nil value)
Traceback
[love "callbacks.lua"]:228: in function 'handler'
main.lua:91: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'
These are the relevant parts of my main.lua:
Code: Select all
Class = require "libraries/class"
push = require "libraries/push"
json = require "libraries/json"
bump = require "libraries/bump"
anim8 = require "libraries/anim8"
function love.load()
math.randomseed(os.time())
local ldtkFile = io.open("game-3.ldtk", "r") [this is line 91]
local ldtkJson = ldtkFile:read("a")
ldtkFile:close()
ldtk = json.decode(ldtkJson)
https://github.com/trashtiergames/snaketime
What I've figured out is that the same error occurs when I run the following from the parent directory:
Code: Select all
love snaketime
Code: Select all
local ldtkFile = io.open("snaketime/game-3.ldtk", "r")
I have tried to get the full path to the directory with this method:
Code: Select all
local current_dir = os.getenv("PWD")
local ldtkPath = current_dir .. "/snaketime/game-3.ldtk"
local ldtkFile = io.open(ldtkPath, "r")
I have also tried the following to get the path:
Code: Select all
current_dir = io.popen"cd":read'*l'
(returns nil)
Code: Select all
current_dir = os.execute("cd")
(returns 0)
Code: Select all
current_dir = debug.getinfo(1).short_src
(returns "main.lua")
Code: Select all
current_dir = debug.getinfo(1).source
(returns "@main.lua")
Code: Select all
current_dir = io.popen("cd"):read()
(returns nil)
These are from this stackoverflow thread:
https://stackoverflow.com/questions/603 ... ory-in-lua
Someone there also recommends installing a library, but I'm not sure if that means it won't work if I send the finished file to friends or let people download it.
So basically I only want to package my game and let other people play it who don't know what lua and love2d is and who can't use the command line. But this error is preventing me from doing that. Can anyone help me?