Page 1 of 2

[SOLVED]Trouble running lua files.

Posted: Mon Jun 17, 2013 2:30 pm
by redhood56_
Hello! Now I know there was a post very similar to this a couple months ago, but it didn't fix my problem. So I am using Goature's tutorial(http://www.youtube.com/watch?v=r0wmvsOI5bw<this part). Okay, since I understand that the code is dated, I downloaded it to see if I missed anything(I missed a line or two in the past parts). Because my version of the code didn't work, I tried the downloaded one. I also got errors. For the downloaded one, I got the error "make sure main.lua is at the top level of the zip". From what I got from the other thread, love2d is case sensitive. The downloaded code's main.lua is actually main(2).lua. When I try to rename them so it is just main.lua I got the other error. Image here: download/file.php?mode=view&id=23054. For my version I got this error:download/file.php?mode=view&id=23055. And when I switch the the lua files from my code to the downloaded code I still get the same error(and when I rename them). Thanks!

Re: Trouble running lua files.

Posted: Mon Jun 17, 2013 2:44 pm
by bartbes
Well, you're probably not packaging his version right.
In any case, the error is because you're using the wrong syntax for require (he is as well, of course). Instead of require("some/file.lua") it should be require("some.file").

Re: Trouble running lua files.

Posted: Mon Jun 17, 2013 8:19 pm
by redhood56_
bartbes wrote:Well, you're probably not packaging his version right.
In any case, the error is because you're using the wrong syntax for require (he is as well, of course). Instead of require("some/file.lua") it should be require("some.file").
oh so you mean like this?

Code: Select all

require("entities.file")
When I do that I still get the error. I also changed all the lines with a ".lua" and the one line with "entities/" too, and it didn't change anything.

Re: Trouble running lua files.

Posted: Mon Jun 17, 2013 8:23 pm
by bartbes
In your case I think you need require("entities"), so basically it's the path, without the file extension, and with any slashes replaced with dots.

Re: Trouble running lua files.

Posted: Mon Jun 17, 2013 9:07 pm
by redhood56_
Ok I did that,which helped, but got me a new error(lol).The error is this download/file.php?mode=view&id=23053. Earlier in the tutorial we created multiple falling boxes on the screen. I think the error has something to do with this line of code

Code: Select all

	register["box"] = love.filesystem.load( ents.objpath .. "box.file" )
Btw, I would like to say thanks so much for the help, i am just starting in game development!

Re: Trouble running lua files.

Posted: Mon Jun 17, 2013 9:14 pm
by Robin
Upload your .love. Click the link in my signature to find out how if you don't know.

In the meanwhile, does a file called "entitiesbox.file" exist?

Re: Trouble running lua files.

Posted: Mon Jun 17, 2013 9:18 pm
by bartbes
No, don't put '.file' after everything! That was just my example. In any case, what you probably want then, is to load a file at location "entities/box.lua", right?
This means that the require should be require("entities.box").

Re: Trouble running lua files.

Posted: Mon Jun 17, 2013 9:21 pm
by MadByte
edit: gd, ninja'd. :D
redhood56_ wrote: Btw, I would like to say thanks so much for the help, i am just starting in game development!
Your're welcome, of course.

It would be easier for us to help when you manage to upload a .love file so we could take a look on what you got so far.
To pack a .love you just have to use a tool like 7-zip or winrar ( on windows ) to pack it to an .zip file and then change the file extension to .love.
more about that - here: Link

Your problem could have a lot of reasons, therefor I would need the source code to tell you what happens.
Basically your error obviously says that the file does not exist, so it isn't already created. If you've started the program thhe first time
it wasn't that hard to fix that:

Code: Select all

if love.filesystem.exists( ents.objpath .. "box" ) then
    register["box"] = love.filesystem.load( ents.objpath .. "box" )
end
This make it load just if it is in your game save directory ( in appdata ).
To completly fix the code I would need the source ;)

a tip: If you just started programming without any knowledge about lua / löve / programming syntax at all it might be better start small
with more simple stuff ! ;)

Re: Trouble running lua files.

Posted: Mon Jun 17, 2013 11:00 pm
by redhood56_
Here is the source code( I hope I did this right)
@MadByte, the tutorial seemed simple, just changing the screen t different colors, and getting images to move across the screen, etc. If there are any other better resources for lua and love2d, could you please point me toward them.
EDIT: It seemed like I forgot to add the zepp texture, I'll update again when I fixed it.
Edit: Download the first one!

Re: Trouble running lua files.

Posted: Tue Jun 18, 2013 6:45 am
by Robin
love.filesystem.load works differently than require, mainly in these three ways:
  • The argument it gets is a file path, not a module name. (So "dir/mod.lua" instead of "dir.mod".)
  • It doesn't "cache" like require does. With require, if you try to load the same thing twice, it does nothing the second time.
  • It returns an executable "chunk" that runs the file, rather than run the file and return what the module returns (which is what require does).
This fixes the first one, I was too lazy to look further:
register["box"] = love.filesystem.load( ents.objpath .. "/box.lua" )