Page 1 of 1
Resources folder?
Posted: Wed Feb 09, 2011 4:45 pm
by Head Over Heels
Hello,
You will have to forgive my complete ignorance but I am just starting out with LOVE and LUA. I am the very definition of a noob.
I'm just playing around with it at the moment and trying to implement that script where you load the image of a hamster, but I am unsure as to where I should be storing the image, or indeed any other images/sounds etc that I may want to use in my functions. I cannot find a resources folder or library. Do I need to create one alongside my script?
This will probably be the first in a series of similarly rudimentary questions. Any help appreciated,
HOH
Re: Resources folder?
Posted: Wed Feb 09, 2011 4:55 pm
by nevon
They can be stored anywhere you want. The path is UNIX-style and relative to your main.lua file.
Here's an example from a real project:
Code: Select all
nevon@nevon-desktop:~/workspace/Love-LD18$ tree
.
|-- arena.lua
|-- bull.lua
|-- conf.lua
|-- fonts
| |-- burnstown_dam.otf
| |-- Chunkfive.otf
| |-- Larabie Fonts License.txt
| `-- SIL Open Font License 1.1.txt
|-- gfx
| |-- bg.png
| |-- bloodparticle.png
| |-- bomb.png
| |-- bull_icon.png
| |-- bulls_caught.png
| |-- bulls.png
| |-- city.png
| |-- comboicon.png
| |-- cowboy_icon.png
| |-- deadplayer.png
| |-- dust.png
| |-- emptyheart.png
| |-- fullheart.png
| |-- gaycity.png
| |-- gore.png
| |-- hat_gripping.png
| |-- hat.png
| |-- hat_spinning.png
| |-- lasso.png
| |-- menucow.png
| |-- minimap.png
| |-- playerspinning.png
| |-- playerwalkanimation.png
| |-- sandtile.png
| `-- walltiles
| |-- bottomleft.png
| |-- bottom.png
| |-- bottomright.png
| |-- gate.png
| |-- left.png
| |-- right.png
| |-- topleft.png
| |-- top.png
| `-- topright.png
|-- lib
| |-- AnAL.lua
| |-- gamestate.lua
| |-- SECS.lua
| `-- soundmanager.lua
|-- main.lua
|-- makelove.sh
|-- minimap.lua
|-- music
| |-- LICENCE
| |-- struttin_rag.ogg
| `-- vestapol.ogg
|-- player.lua
|-- README
|-- sfx
| |-- bombfall
| |-- bombfall.ogg
| |-- chirp.ogg
| |-- CREDITS
| |-- impact.ogg
| |-- ow.ogg
| |-- splat.ogg
| |-- yay.ogg
| `-- yeehaw.ogg
|-- states
| |-- game.lua
| |-- intro.lua
| |-- lost.lua
| `-- menu.lua
`-- utils.lua
In this example, to use topright.png you'd do:
Code: Select all
img = love.graphics.newImage('gfx/walltiles/topright.png')
Re: Resources folder?
Posted: Wed Feb 09, 2011 5:13 pm
by Head Over Heels
Hi, nevon, thanks alot, that is very helpful!!
Re: Resources folder?
Posted: Wed Feb 09, 2011 9:52 pm
by Jasoco
When a Löve game runs, it looks in one of two places. (Are there more?) The .love bundle itself (Which can be a folder or ZIP file) and its resources folder whose location changes depending on what OS you use. (For example, on OS X it's in ~/Library/Application Support/Love/Game_Name/ where Game_Name is either the name of the .love bundle or whatever you manually set it to inside the game. Linux has it under ~/.love/ I think and Windows is in the AppData inside a hidden folder called .love. But I might be completely and utterly wrong. I only use OS X and it might have slipped my mind.)
It looks in the support resources folder first before falling back to the .love bundle. For example, if you have a file called image.png inside both the bundle and the resource folder, it will load the resource one instead of the bundle one. This can be useful for making games that update themselves through patches. Though it also makes it possible for people to just drop properly named files into the right place and change your game completely.
MineCraft does this same thing where it just downloads and runs all its resources from a library folder. And when an update is released, it replaces the current files with the new ones. The application you launch is basically just a front-end that loads whatever is in the folder. Which is why it's so easy to modify MineCraft. Love can download files via the sockets and could have games that also update themselves in much the same manner.
Re: Resources folder?
Posted: Wed Feb 09, 2011 11:05 pm
by Head Over Heels
Thanks for your help, I think I'm now clear on how resources are handled. I'm using Windows, BTW.
Re: Resources folder?
Posted: Wed Feb 09, 2011 11:16 pm
by Jasoco
Head Over Heels wrote:Thanks for your help, I think I'm now clear on how resources are handled. I'm using Windows, BTW.
You're welcome. The folder is hidden so you have to type the path in manually to get it to show up, or turn on hidden files for the correct folder. You won't need to go in there most of the time anyway. Just put all your resources inside the .love bundle. The AppData folder is just where Löve saves files when you use the write commands. (For saving games or preferences for your game)
Start with a single .lua file called main.lua and work from there. As long as you load the other files relative to the root of the .love folder/zip, it will work. If you want to be clean, put files in logical places so it's not just a cluttered mess of .lua's, .png's, fonts and sounds.
Re: Resources folder?
Posted: Wed Feb 09, 2011 11:20 pm
by miko
Jasoco wrote:When a Löve game runs, it looks in one of two places. (Are there more?)
Yes, it looks in standard places for Lua (package.path and package.cpath), and then in "LOVE game directories.", which are OS dependent.
For example, on my linux host:
Code: Select all
$ echo "require 'nosuchfile' > main.lua
$ love .
Checking file main.lua
Checking file nosuchfile.lua
Error: [string "main.lua"]:1: module 'nosuchfile' not found:
no field package.preload['nosuchfile']
no file './nosuchfile.lua'
no file '/usr/share/luajit-2.0.0-beta5/nosuchfile.lua'
no file '/usr/local/share/lua/5.1/nosuchfile.lua'
no file '/usr/local/share/lua/5.1/nosuchfile/init.lua'
no file '/usr/share/lua/5.1/nosuchfile.lua'
no file '/usr/share/lua/5.1/nosuchfile/init.lua'
no file './nosuchfile.so'
no file '/usr/local/lib/lua/5.1/nosuchfile.so'
no file '/usr/lib/lua/5.1/nosuchfile.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file "nosuchfile" in LOVE game directories.
Shared (and library) paths for Lua can be set with environment variables:
Code: Select all
$ LUA_PATH="/tmp/?.lua" LUA_CPATH="/tmp/?.so" love .
Checking file main.lua
Checking file nosuchfile.lua
Error: [string "main.lua"]:1: module 'nosuchfile' not found:
no field package.preload['nosuchfile']
no file '/tmp/nosuchfile.lua'
no file '/tmp/nosuchfile.so'
no file "nosuchfile" in LOVE game directories.
BTW, "current path" (which is ./) would be inside bundle, but other (absolute) paths are global, so watch out for any conflicting file names!.
Example:
Code: Select all
$ echo "NAME='local'" > settings.lua
$ echo "NAME='system'" > /tmp/settings.lua
$ echo "require 'settings'; print (NAME)" > main.lua
$ love .
Checking file main.lua
local
$ LUA_PATH="/tmp/?.lua" love .
Checking file main.lua
system
The package.path and package.cpath are set during compilation time of lua (which is embedded into love). For love it would be safer to set those to "./?.lua;./?/init.lua" and "./?.so". However, thanks to the current package.cpath, I am able to use system-installed libraries from within love script (just by require "module"):
Re: Resources folder?
Posted: Thu Feb 10, 2011 2:22 am
by tentus
Jasoco wrote:... Windows is in the AppData inside a hidden folder called .love. ...
It varies depending on the version of Windows. On my Win7 machine, it is C:\Users\Tentus\AppData\Roaming\LOVE\ (AppData is a hidden file, but you can show hidden files easily).
Re: Resources folder?
Posted: Thu Feb 10, 2011 5:16 am
by TechnoCat
tentus wrote:Jasoco wrote:... Windows is in the AppData inside a hidden folder called .love. ...
It varies depending on the version of Windows. On my Win7 machine, it is C:\Users\Tentus\AppData\Roaming\LOVE\ (AppData is a hidden file, but you can show hidden files easily).
On all windows nt you can get to it with
Re: Resources folder?
Posted: Thu Feb 10, 2011 7:39 am
by tentus
TechnoCat wrote:tentus wrote:Jasoco wrote:... Windows is in the AppData inside a hidden folder called .love. ...
It varies depending on the version of Windows. On my Win7 machine, it is C:\Users\Tentus\AppData\Roaming\LOVE\ (AppData is a hidden file, but you can show hidden files easily).
On all windows nt you can get to it with
True. I just tend to get blank looks when I tell people that: most people can't doubleclick a location bar into giving you %appdata%