Using separate files for some functionality

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
Neekoy
Prole
Posts: 2
Joined: Thu Dec 31, 2015 12:32 am

Using separate files for some functionality

Post by Neekoy »

Heya :)

I'm pretty new here and had a quick question. I'd like to separate some of the functionality in other files, however I'm not sure how to include their functionality in the love.draw(), love.update() and etc. functions.

To be more specific, I'd like to create a window and have all the information for it in a separate file (so I can keep the main file readable) and then to call it in love.draw(), love.update() and to also call functions that might have been declared in that file.

I read about "require", however I am not sure how to create the object I've declared in the other file.

Thanks in advance. :)
Neekoy
Prole
Posts: 2
Joined: Thu Dec 31, 2015 12:32 am

Re: Using separate files for some functionality

Post by Neekoy »

Sorry, after some trial and error it turned out that I can define functions in any file, then "require" it, and then call those functions under whichever LOVE function I want.

Well, since I already wasted your time reading this thread, I think I'd at least say that the engine is great and a whole lot of fun to work with. Thanks for making it :)
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Using separate files for some functionality

Post by s-ol »

Neekoy wrote:Sorry, after some trial and error it turned out that I can define functions in any file, then "require" it, and then call those functions under whichever LOVE function I want.

Well, since I already wasted your time reading this thread, I think I'd at least say that the engine is great and a whole lot of fun to work with. Thanks for making it :)
you should also know that you can return a value (in most cases a table) from a file and save that value when you require it, that way you don't have to pollute the global scope with everything you use.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests