unloading .lua files

I am loading multiple .lua files and it works really well. However, I am currently encountering a serious problem with this method. I have not been able to unload the files, which is preventing me from being able to reload any level that has already been loaded. Does anyone know how to unload files?

–This loads the file from the selection screen
local level3 = require(“Level1”)

–Then I go back to the selection screen

–This no longer loads the file
local level3 = require(“Level1”)
[import]uid: 4871 topic_id: 617 reply_id: 300617[/import]

I don’t think “unloading files” is the solution for your problem. I think you want to make *functions* that create the levels and then call them when you need to. So instead of:

Level1.lua
…code creating level 1…

you want

Level1.lua
function CreateLevel1()
… code creating level 1 (insert stuff into group level1Group)…
return level1Group
end

You then call the CreateLevel() function and insert it when you want to show level 1. Removing the group created for level 1 will remove everything. At a later time you can call the function again… and again. No need for loading/unloading.

Arjan
[import]uid: 4824 topic_id: 617 reply_id: 1207[/import]

1 Like

Ok. I am a little lost. I know what a function is and that they need to be called, but the syntax completely escapes me. Is there any documentation that you can point me to or clarification. The only way I know to do this is with a button function, but that will not work because I think the event will stop.

--------Here is what I understand--------

function CreateLevel1F()
– All My code from my .lua file goes here
end

StartLevel1btn = ui.newButton{default=“OptionsNormal.png”, rollover=“OptionsPressed.png”, onRelease=CreateLevel1F, x = 210, y = 240}

[import]uid: 4871 topic_id: 617 reply_id: 1209[/import]

Thank you so much. You just expanded my capacity to program so much with that one bit of advice. [import]uid: 4871 topic_id: 617 reply_id: 1211[/import]

-Comment Removed

Thanks I just have to reorder everything. I was convinced I was doing it completely wrong when nothing would go away. [import]uid: 4871 topic_id: 617 reply_id: 1212[/import]