Snowhusky5 Posted January 17, 2016 Share Posted January 17, 2016 Hi. I'm trying to make a mod that makes world generation a bit more configurable than it is currently. If I want to slightly change (tack code onto the end of) a single function in worldgen_main.lua, is there an easy way to do that? In the past, I've used one of the AddXPostInit functions in order to slightly change a function on a different aspect of the game, and this will be almost the same. Would I have to use modworldgenmain.lua? Is there an easy way to do this with a function like AddXPostInit? Thanks. Link to comment Share on other sites More sharing options...
DarkXero Posted January 17, 2016 Share Posted January 17, 2016 Which function are you trying to override, and for what? If it's a local function, then you have to copy-paste worldgen_main.lua into your scripts folder and edit that to your liking. If it's a function that will go to the global space (not local), then in modworldgenmain.lua: local _GenerateNew = GLOBAL.GenerateNew GLOBAL.GenerateNew = function(debug, parameters) DoMyThing(debug, parameters) return _GenerateNew(debug, parameters) end Link to comment Share on other sites More sharing options...
Snowhusky5 Posted January 17, 2016 Author Share Posted January 17, 2016 (edited) 10 hours ago, DarkXero said: Which function are you trying to override, and for what? If it's a local function, then you have to copy-paste worldgen_main.lua into your scripts folder and edit that to your liking. If it's a function that will go to the global space (not local), then in modworldgenmain.lua: local _GenerateNew = GLOBAL.GenerateNew GLOBAL.GenerateNew = function(debug, parameters) DoMyThing(debug, parameters) return _GenerateNew(debug, parameters) end It is a local function (AddSetPeices - not a typo, is misspelled in code). Essentially what I'm trying to do is to allow players to determine which set pieces will be enabled and how many of each type will be put into the world. Wouldn't overriding a whole file, especially something like worldgenmain.lua, be pretty bad in a mod, or is there no better way to do it? About the second method, is there a way to make code run somewhere in the middle of a pre-existing function rather than only before or after? Edited January 17, 2016 by Snowhusky5 Link to comment Share on other sites More sharing options...
DarkXero Posted January 17, 2016 Share Posted January 17, 2016 1 hour ago, Snowhusky5 said: Wouldn't overriding a whole file, especially something like worldgenmain.lua, be pretty bad in a mod Yes, if there are many world gen mods that try to do something that requires intrusive changes. Only the last worldgen applied will be valid. 1 hour ago, Snowhusky5 said: is there no better way to do it? I can't see any way to hook into those functions, or change their values to something specific outside the "multiply" table, from outside. Because they are locals, they are essentially blackboxed. 1 hour ago, Snowhusky5 said: About the second method, is there a way to make code run somewhere in the middle of a pre-existing function rather than only before or after? Unless you can hook into a function that is used in the middle of the function you do want to edit, then no. function MidFunc() end function EditThis() DoOne() MidFunc() DoTwo() end There you have access to MidFunc, and to the middle of EditThis. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now