That would work if the game is launched using the .love file.
Sorry I only tested it with a .love file and figured that it would work with .exe's as well Opps!
Ubermann wrote:
But for a standalone binary, arg[1] is nil unless the player sets launch parameters like "./mygame -a"
Using the following code in a .bat file it works (it isn't a great work around but it does the job.) (I will have to make equivalents for macs and linux)
for /F %%x in ('CHDIR') do set path=%%x
testGame.exe "%path%/testGame.exe"
Now there are two files (launch.bat and testGame.exe) but I'd like to combine everything into one big happy .exe by using the following in command prompt:
I found another solution! This one doesn't use a .bat file. I used the LoveFS lib to make executing os commands a little easier. Here's the code in main.lua
require 'lovefs/lovefs'
function love.load()
fs = lovefs()
if not(arg[1]) then
if love._os == 'Windows' then
a, b = fs:run('cd')
b = b..'\\'
else
a, b = fs:run('pwd')
b = b..'/'
end
else
b = arg[1]
end
end
function love.draw()
love.graphics.print( b..'test.exe', 0, 0)
end
After some testing I found that it won't work if the game is launched from the terminal
or of course if the file was renamed.
Attachments
Untitled.png (1.47 MiB) Viewed 3448 times
My Tox ID: 0F1FB9170B94694A90FBCF6C4DDBDB9F58A9E4CDD0B4267E50BF9CDD62A0F947E376C5482610