Hello.
Just pursuing my discovery of “script properties” there.
I wanted to know how heavy are LUAC files if you REQUIRE them in instances. Like, a few hundred instances.
Basically, two object, each with its script : Galaxy & Stars
In the INIT of Galaxy, a loop and a lot of datas in LOCAL variables/tables.
The loop, going from 1 to a few thousands (depends of the player), create as many Instances of Stars, and send to each of it its data by Property :
factory.create("#Stars", nil, nil, {Etoile_Type = number, Etoile_Taille = number2, Number_Orbits = Number_Orbits}, nil)
Each “stars” use its property datas in Init (they are SELF type, of course).
Galaxy init also put some of other datas in a GLOBAL table
Result intended :
- Galaxy : Lot of datas are put on LOCAL variables (they are to be used only in this INIT)
- Galaxy : 1 to X’100s instances of Stars created
- Stars : Each instance has it’s own datas in SELF variables, sent to it by Property.
- Galaxy : A GLOBAL table is created.
- Galaxy : Everything else in the INIT is deleted when INIT end, including all the LOCALs (the script put in the GLOBAL table what it wants to keep)
But you can’t send Tables by Properties…
A pain, If you ask me.
Then, If I don’t want to keep all the datas I need instancied ALSO in some gigantic GLOBAL, I have to use a LUAC ?
Then, question, since I don’t find answers in the manuals :
- Can I require in INIT, or does I have to do it before ?
- The LUAC is going to contain a lot of datas (LOCAL + code) I don’t need after the Stars objects are created. Is there a mean to, you know, delete it from memory ?
- Are the LOCAL in the luac deleted, as if I undertand they would be after an Init end ?
- Are the GLOBAL created in the LUAC kept (I want yes, of course).
This page [Lua modules in Defold] say the “module” that is the LUAC is declared “local”, but it still have to be required out of the “INIT” function, meaning it’s more a “self” than a “local” (again, if I understand)
I see also “package.loaded[“my_module”] = nil”, but where I could put it for it not be used before the different instances stopped to need it ? Is this order delete also the LOCAL in it (I want yes) ?
Basically, there is a lot of code/data that are needed at the creation of the instances I never need after that, with the exception of some I put in a Global.