Jump to content

require syntax keyword questions


XainFaith

Recommended Posts

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

The function that i wish to call is a global function 

 

for example

function PostProcess()---Do some post initalization here ---end

and in modmain

local require = GLOBAL.require---in sim init---function SimInit()require "PostProcess/PostProcess"PostProcess()end

Regards XainFaith

Link to comment
Share on other sites

@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 call

require "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

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

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

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.

×
  • Create New...