## The functon require no succeed two Times

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Jose_antonio_920
Prole
Posts: 7
Joined: Wed Jul 15, 2020 10:56 pm

### The functon require no succeed two Times

Frist i not know speak english, my english is bad. In my code i use one require in one archive, but o try reset the archive Using require but no suceed, Nothing change, o try use setmetatable for create one clone but no succeed. What I can do?
MrFariator
Party member
Posts: 263
Joined: Wed Oct 05, 2016 11:53 am

### Re: The functon require no succeed two Times

When you load a file with require, it caches the result so to avoid duplication of work on subsequent requires to the same file. The files loaded with require can be accessed via the global "package.loaded":

Code: Select all

print(package.loaded["myfile"]) -- prints nil
require("myfile")
print(package.loaded["myfile"]) -- prints something like table: 0x0026f0a8 
So, if you really want to empty the cache and require a file again, you could set the corresponding entry in package.loaded to nil:

Code: Select all

package.loaded["myfile"] = nil -- clears the cache for "myfile"
require("myfile") -- because the cache was emptied, require loads the file again
However, I wouldn't necessarily recommend this approach, as messing with require cache seems dirty to me. Perhaps you could use something like love.filesystem.load for this purpose instead, or make your file return a function that you can simply call to create an instance of whatever class or data the file represents? Depends on what your exact use case is, I reckon.
Jose_antonio_920
Prole
Posts: 7
Joined: Wed Jul 15, 2020 10:56 pm

### Re: The functon require no succeed two Times

Eeeeee i try verry, but all objects create self clone, i try use dofile but no know how find the path complete
MrFariator
Party member
Posts: 263
Joined: Wed Oct 05, 2016 11:53 am

### Re: The functon require no succeed two Times

Can you post your code? It'll make it easier to help.
Jose_antonio_920
Prole
Posts: 7
Joined: Wed Jul 15, 2020 10:56 pm

### Re: The functon require no succeed two Times

Sorry, i am resolved, its existed two archiver for restart

### Who is online

Users browsing this forum: No registered users and 16 guests