Jump to content

What if I wanted to write my own mod: WHERE IS REFERENCE (API) DOCUMENTATION?


sisteczko

Recommended Posts

I am a professional programmer. I know Lua. I want to dedicate some time to write a mod or two (so I can teach my kid, who loves the game, some basic programming skills).

 

Usually I would start from reading official library documentation. But I can't find any "manual", "handbook" or even tutotial that explains all basic stuff in order. What I find here, is a bunch of "Howtos" with no systematic treatment of anything, half explaining things I don't want to know at this stage, and usually ommiting some basic premises of the whole modding system in Don't Starve.

 

Specifically, I have the following problems:

 

  1. Which functions are hard-coded by the game itself (i.e. not defined in the game scripts)?
  2. Which functions from the game scripts are meant to be overloaded (overwritten) by mods? I know I can replace arbitrary function in Lua, but when the game gets upgraded I might be left with a broken mod.
  3. What is the order of script execution of the game on server side? Which Lua function gets called and when? I guess routines associated with "worldgen" gets called only the first time the server is called (unlike in e.g. Minetest/Minecraft) and never afterwards.
  4. What is the order of script execution of the game on client side? Which Lua function gets called and when?
  5. How exactly communication between Server and Client works? Do they simply share a state of the world? And what exactly constitutes the state? What things client can change, and what must be done on server?

 

After I know that, I think I can infer all the rest by reading the Lua scripts provided by the game and modders. But before that, I feel like walking in a mist.

 

Like I said, I am a professional programmer. I don't want a "how to program in Lua" tutorial or "what is an anonymous function" explanation.

Link to comment
Share on other sites

@sisteczko, there was an unofficial API documentation. The site is no longer up, but I released the (in its current state unreadable) backup files. They are mostly about the scripts though, so of little interest to you.

 

Anyways...

  1. There's no real way to find that out other than studying scripts, at least I know of none. Maybe you are able to loop through the elements of a table in order to print them.
  2. You can use a set of functions specifically made for mods, such as AddPrefabPostInit("prefabname",function(instance) end)
  3. Wrong forum, you meant to ask this in the DS Together modding forums.
  4. Fun Fact: you can enable mod debug print to show additional mod loading info in the log.txt
  5. Unfortunately I am really bad at modding DST so I can't really help you with that.

 

Life is walking in the mist of perception, so that tiny section of your life being in mist on its own shouldn't worry you too much.

Yes, I am self-learnt.

 

If you really need Klei's support, you can notify any forum member by selecting arbitrary text from their post and clicking "@mention" or by clicking the "quote" button at the bottom of their post. Peter A. is very active in the DST modding forum.

Link to comment
Share on other sites

Unfortunately there is no official documentation. Modding is highly supported, there is a basic API, and a set of tools (the Don't Starve Mod Tools, found in Steam's "Tools" tab), but the devs do not have the the time or obligation to document the code. The modding community seems to get along fine without it, especially due to these forums.

 

1. The rule of thumb is that most functions are coded in the lua. 'TheSim' and it's functions are all in C(++?). You can probably use lua's debug commands to check this manually.

 

2. The game's API is rarely changed, I doubt that upgrades would occur that would break your code (A new DLC for normal Don't Starve is coming out though, so compatibility with that may be an issue). Oftentimes overrides are necessary to attain functionality not possible with the normal code.

 

3. As Mobbstar said, this is the Don't Starve (base, singleplayer game) forum. I don't know about the activities on the DST forum, but you can certainly ask questions here that do not concern networking, and they will likely be answerable. There should be enough tutorial materials and local expertise on the other forum to introduce you to DST modding.

 

In regard to worldgen:

When you create or create, resume, or travel to a world (such as a cave or adventure mode level), the game updates it's persistent state and loads a new instance. If the requested world does not yet exist, the game will run a series of special code for worldgen instances, then reload again. The file 'modworldgenmain.lua', if it exists in your mod, will be run in this instance, before worldgen.

 

4. No idea, probably not terribly relevant to content creation. Figure it out via debugging if you ever encounter a situation where you need to know.

 

5. Again, we of this forum don't really know. The HUD is certainly client side, but the animations might not be. Standard functionality will probably be server side. I suggest you puzzle it out using the code, or debugging. Again, is likely enough basic information to at least get you started.

 

Might I suggest you try modding Don't Starve instead of DST? It would likely be far easier to pick up, and less prone to changes in the code.

Link to comment
Share on other sites

On 1/26/2016 at 8:47 AM, Ishvii said:

How are you meant to know what to change if the API isn't written down anywhere? :(

Experiment? Perhaps it is deliberate, to help promote interactions within the community.

 

The unofficial API site is operational(ish) again, you can find it here. Hopefully this will be helpful.

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...