Page 1 of 1

[0.17.79] util.ismoduleavailable throws when the argument is not already loaded

Posted: Mon Nov 25, 2019 7:25 pm
by justarandomgeek
It looks like this was intended in the past to solve the problem of "require these files if they are available", but fell out of use in favor of the is_demo flag, and then was unnoticed when `package` was stripped. It now throws a scripterror when it attempts to use `package.searchers or package.loaders`, which happens for anything not already loaded.

I currently solve this problem with cross-mod requires using `pcall(require,"__modname__/filename.lua")`, but if this function worked I could simply test first and get rid of the pcall.

Re: [0.17.79] util.ismoduleavailable throws when the argument is not already loaded

Posted: Tue Nov 26, 2019 12:38 am
by Rseding91
Thanks for report. I deleted the function since it's no longer valid anyway. You can check if a mod exists by checking "if mods[name]" before doing the require. If you don't know if the file exists even if the mod exists I question why anyone would want to write that code.

Re: [0.17.79] util.ismoduleavailable throws when the argument is not already loaded

Posted: Tue Nov 26, 2019 1:27 am
by justarandomgeek
Rseding91 wrote: Tue Nov 26, 2019 12:38 am Thanks for report. I deleted the function since it's no longer valid anyway. You can check if a mod exists by checking "if mods[name]" before doing the require. If you don't know if the file exists even if the mod exists I question why anyone would want to write that code.
The `mods` table isn't available in control stage. game.active_mods doesn't become available until after require stops working.

I suppose moving active_mods from game to script would also meet my needs.