[Solved]Lua Script flush old script

Hi all,

I create a lua project by Cocos Code IDE

In this project it will download new lua file and start to execute,

the lua file has same name but I put it in difference folder,

and update search path,

but it still execute old lua file

I has used

cc.FileUtils:getInstance():purgeCachedEntries()

some ideal please. THX

I think I find the solution,

before i require data i use

package.loaded[‘your_file_name’] = nil

it will let lua engine reload that script

then I require the file it will load the new script file.

thanks all. :smiley:

Which version of Cocos Code IDE did you use?
How did you update search path, addsearchpath or setsearchpath?

My environment Cocos2d-x v3.3, Code IDE v1.1.0

I backup the search path and package.path before script turning,

-- backup search path
backupPackagePath = package.path

-- backup resource search paths
backupSearchPaths = cc.FileUtils:getInstance():getSearchPaths()

-- restore original search paths
cc.FileUtils:getInstance():setSearchPaths(backupSearchPaths)

-- restore original package path
package.path = gBackupPackagePath

and then

-- update new package path
package.path = newGameSrcPath .. "?.lua;" .. backupPackagePath

-- add new search paths
cc.FileUtils:getInstance():addSearchPath(newGameResPath, true)
cc.FileUtils:getInstance():addSearchPath(newGameSrcPath, true)

Good Luck