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
Before you make a thread asking for help, read this.
Post Reply
Jose_antonio_920
Prole
Posts: 8
Joined: Wed Jul 15, 2020 10:56 pm

The functon require no succeed two Times

Post by Jose_antonio_920 »

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: 509
Joined: Wed Oct 05, 2016 11:53 am

Re: The functon require no succeed two Times

Post by MrFariator »

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: 8
Joined: Wed Jul 15, 2020 10:56 pm

Re: The functon require no succeed two Times

Post by Jose_antonio_920 »

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: 509
Joined: Wed Oct 05, 2016 11:53 am

Re: The functon require no succeed two Times

Post by MrFariator »

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

Re: The functon require no succeed two Times

Post by Jose_antonio_920 »

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

Who is online

Users browsing this forum: Bing [Bot] and 22 guests