Jump to content

Recommended Posts

Hello everyone,

 

i have read all trough the tutorials i could find and was able to make quite a number of own mods but as more and more updates roll out i get more and more confused about some of the incompatibilities which are raising up and in comment section of other mods i sometimes read about the term "Proper API style" so i wondered if there is actually a complete documentation about how to do stuff in the best way for most cases but i couldn't find anything like that yet, so i hope you can explain to me what's the fuzz about :-)

 

The best thing i could find by now was the well known API examples in which the use of all add[...]postinit functions are explained and one thread here on the forums explaining how to properly overwrite functions in lua, is there anything more to know?

 

I'm only writing simple mods btw which are mostly just modifiying some values here is an example:

local require = GLOBAL.requirelocal TUNING = GLOBAL.TUNINGlocal IsServer = GLOBAL.TheNet:GetIsServer()local worldState = require "components/worldstate"local propagator = require "components/propagator"local fpm = GetModConfigData("FIRESPREAD")--config          local heatm = GetModConfigData("FIRESPREADHEAT")--config local spreadOnRain = GetModConfigData("SPREADONRAIN") local spreadOnSnow = GetModConfigData("SPREADONSNOW")--config--local propagatorStartSpreadingBase = propagator.StartSpreading or function() return true end--function propagator:StartSpreading(source,...)--    self.propagaterange = self.propagaterange * fpm--   return propagatorStartSpreadingBase(self,source,...)--endAddComponentPostInit("propagator", function(inst) inst.propagaterange = inst.propagaterange * fpm end)local propagatorAddHeatBase = propagator.AddHeat or function() return true endfunction propagator:AddHeat(amount,...)   amount = amount * heatm   return propagatorAddHeatBase(self, amount,...)end local propagatorOnUpdateBase = propagator.OnUpdate or function() return true endfunction propagator:OnUpdate(dt,...)    local isSnowing = false    local isRaining = false    local issnowcovered = false    local snowlevel = 0    if TheWorld and TheWorld.state then        isSnowing = TheWorld.state.issnowing        isRaining = TheWorld.state.israining        issnowcovered = TheWorld.state.issnowcovered        snowlevel = TheWorld.state.snowlevel    elseif GLOBAL.TheWorld and GLOBAL.TheWorld.state then          isSnowing = GLOBAL.TheWorld.state.issnowing        isRaining = GLOBAL.TheWorld.state.israining        issnowcovered = GLOBAL.TheWorld.state.issnowcovered        snowlevel = GLOBAL.TheWorld.state.snowlevel    elseif worldState and worldState.data then        isSnowing = worldState.data.issnowing        isRaining = worldState.data.israining        issnowcovered = worldState.data.issnowcovered        snowlevel = worldState.data.snowlevel    else        print("WorldState couldn't be found!")    end    if((isRaining and not spreadOnRain) or ((isSnowing or issnowcovered or snowlevel > 0 ) and not spreadOnSnow))  then       self:StopSpreading()    end    return propagatorOnUpdateBase(self,dt,...)end

I'm also almost sure i did something wrong there :)

@ForenSmurf, here is the short answer, Proper API coding is not overwriting files in the scripts folder. You use the provided code such as AddComponentPostInit, AddPrefabPostInit, etc. to make changes to the already existing code.

 

Unfortunately not everything is easily done this way because not everything is coded for mods to have access to change. If you come across a file or area that is like that you should post about it here and let PeterA know so that he may look into making it more mod friendly. 

I've been looking for a proper API documentation as well. From what I understand the problem is that the devs don't want to or don't have time to write up a good (or comprehensive) api documentation. I can't blame them for this, they have other work to do.

 

I actually was thinking that this could probably be solved if they added an official modding api wiki that could be edited by modders. This could become a comprehensive wiki that would include everything a modder needs to know about the don't starve api.

Hey @LastTalon, there isn't an official wiki for this information yet, but some of the modders in the community have been putting together their own unofficial documentation. http://dontstarveapi.com/

 

Wow that looks awesome, thank you :)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...