XainFaith Posted October 21, 2013 Share Posted October 21, 2013 Hello there again i am having an issue and i am wondering if anyone knows if there is a way to deal with it. I have a global function in a script we shall just call this script B.i want to call this function in modmain but even when using require it tells me that i am call on a null (nil) value. Just in case you are curious as to why i want to do this it is mostly just for structure and keeping things organized i dislike to a very large degree to have everything crammed into one file. Regards XainFaith Link to comment Share on other sites More sharing options...
Malacath Posted October 21, 2013 Share Posted October 21, 2013 Even require needs GLOBAL to call it. That might be your problem.Otherwise a concrete example on how the file you require looks like and how you want to call a function within might be helpful. Link to comment Share on other sites More sharing options...
XainFaith Posted October 21, 2013 Author Share Posted October 21, 2013 The function that i wish to call is a global function for examplefunction PostProcess()---Do some post initalization here ---endand in modmainlocal require = GLOBAL.require---in sim init---function SimInit()require "PostProcess/PostProcess"PostProcess()endRegards XainFaith Link to comment Share on other sites More sharing options...
Malacath Posted October 21, 2013 Share Posted October 21, 2013 I found this here in one of simplex's modsmodimport("submodules/consoleutils.lua")I'm not quite certain how the syntax is there though. Maybe he can help out. Link to comment Share on other sites More sharing options...
XainFaith Posted October 21, 2013 Author Share Posted October 21, 2013 Thanks ill give that a shot and let you know how it goes, seems like that is probally some api from lua version ds has. Regards XainFaith Link to comment Share on other sites More sharing options...
simplex Posted October 21, 2013 Share Posted October 21, 2013 @XainFaith (and @Malacath)The issue with your use of require is that it runs the file in the global environment, not the mod one, so you'd need to call PostProcess() as GLOBAL.PostProcess(). Alternatively, if the require()'d file returns something (just like a function, with a return statement), that's the return value of the require() call, so you can return PostProcess from it (or a table with other things as well). The callrequire "PostProcess/PostProcess"will look for "PostProcess/PostProcess.lua" in its path (within the scripts/ folders of mods first, and then in the game one inside data/), running it in the global environment upon finding it (and raising an error otherwise). Also, a require()'d file only runs once, i.e. further require() calls to it will not run it again (but will give you its return value, if any).modimport(), on the other hand, is a function from the DS mod api. It runs a file relative to the mod folder. Its main differences when compared to require is that the file runs in the mod environment, that its path is taken relative to the base mod folder (and not its scripts/ subdirectory), that the ".lua" extension needs to be given and that modimport()'ing a file several times will make that file run every time (so, if switching to modimport(), you'd want to put the modimport() call outside of the SimInit function).EDIT: Also, modimport() ignores the return value of the file, if any. It always returns nil. Link to comment Share on other sites More sharing options...
XainFaith Posted October 21, 2013 Author Share Posted October 21, 2013 Thanks for those details that gives me all the information i required. is there any good documentation on the events that one can hook into for post processing as well as pre processing. But as for this thread the question that was asked has been answer so if a moderator wishs to mark it as answered i am ok with that. Regards XainFaith Link to comment Share on other sites More sharing options...
simplex Posted October 21, 2013 Share Posted October 21, 2013 Thanks for those details that gives me all the information i required. is there any good documentation on the events that one can hook into for post processing as well as pre processing. I believe the best documentation is still the code in modutil.lua and the sample mods. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.