Finding myGame.exe path

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
I~=Spam
Party member
Posts: 206
Joined: Fri Dec 14, 2012 11:59 pm

Finding myGame.exe path

Post by I~=Spam »

Is it possible to get the directory a love game that was launched?
unknown/path/to/myGame.exe

I don't think that there is a way but I couldn't find a post about it and thought it was worth asking :D
Last edited by I~=Spam on Wed Dec 26, 2012 5:49 pm, edited 2 times in total.
My Tox ID: 0F1FB9170B94694A90FBCF6C4DDBDB9F58A9E4CDD0B4267E50BF9CDD62A0F947E376C5482610
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Finding myGame.exe path

Post by Robin »

arg[1]
Help us help you: attach a .love.
User avatar
I~=Spam
Party member
Posts: 206
Joined: Fri Dec 14, 2012 11:59 pm

Re: Finding myGame.exe path

Post by I~=Spam »

Thanks works great! :ultraglee:
My Tox ID: 0F1FB9170B94694A90FBCF6C4DDBDB9F58A9E4CDD0B4267E50BF9CDD62A0F947E376C5482610
User avatar
Ubermann
Party member
Posts: 146
Joined: Mon Nov 05, 2012 4:00 pm

Re: Finding myGame.exe path

Post by Ubermann »

Robin wrote:arg[1]
That would work if the game is launched using the .love file.


But for a standalone binary, arg[1] is nil unless the player sets launch parameters like "./mygame -a"
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: [Solved] Finding myGame.exe path

Post by Robin »

Is that right? I thought that would give the path to the executable in that case. (Not inclined to test it right now.)
Help us help you: attach a .love.
User avatar
I~=Spam
Party member
Posts: 206
Joined: Fri Dec 14, 2012 11:59 pm

Re: Finding myGame.exe path

Post by I~=Spam »

Ubermann wrote:
Robin wrote:arg[1]
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 :o 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)

Code: Select all

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:

Code: Select all

copy /b launch.bat+love.exe+testGame.love testGame.exe
which of course doesn't work. :x

Is it possible to add all of the files together into one .exe?
My Tox ID: 0F1FB9170B94694A90FBCF6C4DDBDB9F58A9E4CDD0B4267E50BF9CDD62A0F947E376C5482610
User avatar
I~=Spam
Party member
Posts: 206
Joined: Fri Dec 14, 2012 11:59 pm

Re: Finding myGame.exe path

Post by I~=Spam »

I found another solution! :ultrahappy: 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

Code: Select all

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
Untitled.png (1.47 MiB) Viewed 3435 times
My Tox ID: 0F1FB9170B94694A90FBCF6C4DDBDB9F58A9E4CDD0B4267E50BF9CDD62A0F947E376C5482610
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 4 guests