modules dont work

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
fixylol
Prole
Posts: 21
Joined: Thu Feb 25, 2016 2:16 am

modules dont work

Post by fixylol »

on the top of my script, i put

Code: Select all

require("Level.lua")
, yet for some reason despited Levels.lua actually existing within the game folder it threw an error saying it doesn't exist in the path i put love itself in...
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: modules dont work

Post by bartbes »

Require does not take file names, it takes module names. To translate a module name into a filename, you replace all dots with slashes, then append .lua. (Or see [manual]package.path[/manual] or [wiki]love.filesystem.setRequirePath[/wiki].) So in your case, you should be using:

Code: Select all

require("Level")
And I should note that zips are case-sensitive, so make sure that matches too.
fixylol
Prole
Posts: 21
Joined: Thu Feb 25, 2016 2:16 am

Re: modules dont work

Post by fixylol »

bartbes wrote:Require does not take file names, it takes module names. To translate a module name into a filename, you replace all dots with slashes, then append .lua. (Or see [manual]package.path[/manual] or [wiki]love.filesystem.setRequirePath[/wiki].) So in your case, you should be using:

Code: Select all

require("Level")
And I should note that zips are case-sensitive, so make sure that matches too.
thanks :D

but now i have another problem... for some reason pairs() thinks a table is the number 14 (i used v, not i)
bobbyjones
Party member
Posts: 732
Joined: Sat Apr 26, 2014 7:46 pm

Re: modules dont work

Post by bobbyjones »

fixylol wrote:
bartbes wrote:Require does not take file names, it takes module names. To translate a module name into a filename, you replace all dots with slashes, then append .lua. (Or see [manual]package.path[/manual] or [wiki]love.filesystem.setRequirePath[/wiki].) So in your case, you should be using:

Code: Select all

require("Level")
And I should note that zips are case-sensitive, so make sure that matches too.
thanks :D

but now i have another problem... for some reason pairs() thinks a table is the number 14 (i used v, not i)
Show code. Also what vars you use don't matter

Code: Select all

books ={}
books["Book of Bartbes"] = "a bunch of text"
books["How to make things with LOVE"] = "even more text"
for title, content in pairs(books) do
    print(title)
end 
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Bing [Bot] and 8 guests