Re: [bug ?] error exporting external scripts
Posted: Thu Oct 30, 2014 2:37 pm
Placed in the Superthread : Editor issues ^^
Official Legend of Grimrock Forums
http://almosthumangames.com/forum/
Ok scratch that; this is a bump for confirmation or work around from a dev so I can play my module outside the editor. Don't worry I'll try to keep it to one bump every couple days after this one. ~laughs~ ...unless, I'm the last person who can not Export, then I'll just throw my towel in and move on.NutJob wrote:This is not a bump to catch the attention of a Dev[...]
Code: Select all
function loadScript(entityName,scriptPath)
if findEntity(entityName) then
Console.warn('Entity named '..entityName..' already exists')
return false
end
local scr = spawn('script_entity',party.level,1,1,1,1,entityName)
scr.script:loadFile(scriptPath)
end
loadScript('test','mod_assets/jkos/my_test.lua')
loadScript('otherScript','mod_assets/jkos/my_other_test.lua')
If I simply understood, this script consider external scripts like "items". When spawning them, we give an iteration and so, can destroy them like other items. Really wonderful/useful/epicness !JKos wrote:And as a bonus you don't have to place those script-enties by hand, they are created dynamically. And this means that we can load and destroy scripts any time we want, may be useful for really large and complex dungeons, like orrr3, maybe.
Appreciate the work around. While it's loading I'm now having a problem with the namespace and I'll have a lot syntax and hierarchy to rework before I can confirm it's [personally] working. I'm sure it does, though. Thanks.JKos wrote:Here is a workaround for you
Tested and it even seems to be save game compatible . This will make loading huge libraries with multiple scripts a breeze.Code: Select all
function loadScript(entityName,scriptPath) if findEntity(entityName) then Console.warn('Entity named '..entityName..' already exists') return false end local scr = spawn('script_entity',party.level,1,1,1,1,entityName) scr.script:loadFile(scriptPath) end loadScript('test','mod_assets/jkos/my_test.lua') loadScript('otherScript','mod_assets/jkos/my_other_test.lua')
And as a bonus you don't have to place those script-enties by hand, they are created dynamically. And this means that we can load and destroy scripts any time we want, may be useful for really large and complex dungeons, like orrr3, maybe.
That is what I did and it can find the script_entity ('lib.script') but once it gets to my [fake] namespace "GFX" it drops me errors. The external file starts:JKos wrote:What kind of namespace problems? I didn't test this much, but doesn't it work if you remove/rename your external script entites and instead load them with loadScript-method?
I mean if you have a external script entity named "lib" which points to "mod_assets/nutjob/lib.lua", just remove it from the dungeon and call loadScript("lib","mod_assets/nutjob/lib.lua")
Code: Select all
GFX = {}
GFX.v = {}
-- followed by all functions under
GFX.myfunctionA = function() end
GFX.myfunctionB = function() end
-- and so on, using GFX.v to store any variables that need to be saved (or the odd parameter pass to something else, like when using delayedCall)
Code: Select all
lib.script.GFX.getSomethingAndDoit()
Code: Select all
function test()
lib.script.GFX.getSomethingAndDoit()
end