Ultroman

Ultroman's Tutorial Collection + Newcomer Intro

Recommended Posts

Ultroman    717

>>  The Newcomer Intro Post  <<

Welcome to the world of Don't Starve modding! :D

There are a bunch of things you should do, in order to make your life easier going into this.

  • Get yourself a nice text editor. I use Notepad++ and can highly recommend it. Make sure to set the "Language" to "Lua" while you're coding in Lua (the language we use for modding). That'll help you greatly in many ways. The "Find in files" function is also useful, for finding examples of code usage in the game files (CTRL-SHIFT-F in Notepad++, and make sure the filter is either *.* or the extension of the files you want to search in, e.g. *.lua, and also make sure to set Match Case etc. to what you want). Sublime is another great text editor. There are many!
  • Take a Lua crash course. Here's a quick text-based crash course for already experienced coders and here are two crash courses in video-form, the first (12 min) basically goes through the Lua Manual while the second (15 min) does its own thing. It WILL save you LOADS of time and frustration to learn Lua first. I'm not kidding. Do this for yourself. You need to know how the syntax and the peculiar table/object model work to form everything from a light, to a list of strings, to a full player object. There is very little help from the language itself, so things like searching through a list is something you have to make yourself or find from a code resource.
    You might be asking how to do tutorials in Lua when you haven't even set up a mod yet. You can use this Online Lua Interpreter to play around.
  • Look in the FAQ for general information.
  • You'll find the game code scripts in:
    • DS: steamapps\common\dont_starve\data\scripts
      You'll find the new/changed data files for each DLC in: steamapps\common\dont_starve\data\DLC000#
    • DST: steamapps\common\Don't Starve Together\data\databundles\scripts.zip
      Unpack that somewhere far away from your game folder. In the "prefabs" folder you'll find all the entities in the game (players, items, creatures, bosses etc.). Some prefabs files hold more than one prefab, like spider.lua and cavespiders.lua which have several creature prefabs in them, and e.g. the amulet.lua and hats.lua which have several item prefabs in them. Everything in the game is made up of components, which are in a separate folder. Living creatures have brains (AI) and stategraphs (a collection of states they can be in and actions they can perform, which together determine how they operate. It also handles a lot of the waiting for and switching of animations etc. based on the actions performed) and these are in separate folders, as well. The UI-stuff is mostly found in the widgets folder.
  • Look at the amazing collection of modding tips and tutorials you can find in this forum section (DS) and this "getting started with modding guide" thread (DST). Both have some overlap between DS and DST. There are some for working with items, images and animations. Of course, there is also the list I've compiled in the first post in this thread.
  • Learn the basics of the files involved in mods. I have a post here explaining the contents of modinfo.lua.
  • Some information about mod icons.
  • To see how working mods are made, download a few mods, and look at their code. I can recommend this one for a simple TUNING-variable tweak, and CactusArmor.zip for a simple armor (although it is a DST mod, I think the code should work for both DS and DST, except the api_version in modinfo.lua).
  • Look at the tutorials I've listed in the first post of this thread. Even if you don't understand everything that's going on, it should still help you understand bit by bit how things are done. There are many moving parts, so don't expect to just push out a mod on your first day...at least not a bug-free one :)
  • When you're completely baffled by something, try to find an existing mod that does something very similar to what you're doing. You can usually figure out what they're doing or it'll give you some new insight to help you progress.

 

Searching the forum

"I know how to search a #%&€ forum!" Yeah, but this one is special. When using the search bar at the top, it defaults to searching all the forums, not just the modding forums, so you'll get search results for all Klei's games and all the forums they have, not just the modding forums. These are the two easiest ways I've found to search for modding threads. One (normal forum search) allows you to search exclusively for threads for one of the games, and is probably the most easily accessible, while the other method (advanced search) allows you to search for threads for both games (DS and DST) at the same time OR exclusively one of the games.

Normal modding forum search, when searching exclusively for DS or DST, but NOT BOTH:

Advanced modding forum search, when you don't care whether the thread is for DS or DST:

  • Click the search-bar at the top of the page
  • Type in any search term and press enter or click the spyglass.
  • On the next page, click on "More search options" underneath the search term bar.
  • Select "Topics" on the left
  • In the "Forums" dropdown below, scroll downwards and select BOTH
    [Don't Starve Together] Mods and Tools
    and
    [Don't Starve] Mods and Tools
    from the list.
    The content is kind of muddled together between the games, despite the mods trying their best to keep them separate, but much of the code can be used for either game. Just be aware that there are differences between the two games, and that you might sometimes need to make slight changes or even take a completely different approach for certain functionality between the games. If you want to be at least almost sure not to have this problem, only select the forum for the game you are modding for.
  • Then type in your search at the top, and press Enter or the magnifying glass

 

Debugging

In order to see the full error log, which has more information than the game has room on the screen to show you, and also shows what might have lead to the error, you need to look at the game logs.

For DS there's only one log. It's called "log.txt" and it's right here:

<SystemDriveLetter>:\Users\<UserName>\Documents\Klei\DoNotStarve

For DST, there are two "types" of logs.

If your game crashed while playing, the error is most likely found in your server_log.txt file(s). If your server has caves in it, there will be a server_log.txt for both the regular server "shard" and the caves server "shard". You can find those files here:

<SystemDriveLetter>:\Users\<UserName>\Documents\Klei\DoNotStarveTogether\Cluster_#
(# = 1-5; this is the placement of your server on the list of servers in-game)

In that folder, you will find a "Master" folder and perhaps also a "Caves" folder. Both should have a server_log.txt in them.

There is also a client_log.txt. If the game dies in the main menu or while loading the game or on the character select screen, in which case there might not be any server_log.txt files, you can still find the client_log.txt file here:

<SystemDriveLetter>:\Users\<UserName>\Documents\Klei\DoNotStarveTogether

These files are crucial for us to help you, when you're asking how to fix a crash. Attach those files to your crash post, by dragging and dropping them onto the reply you are about to submit, and if you suspect that it's your mod causing it, also post a zip of your mod.

You can also use those files to your advantage when debugging your mod. If something in your mod is not working, or even if it is crashing during play, you can give yourself lots of hints and information about what code is actually being executed and which parts are not. You do this by using print-statements, like shown below. These print-statements show up in the client_log.txt, which you can even look at while the game is playing (Notepad++ should automatically ask you to reload the file if you come back to it after it has been changed, but not always!!).

-- Simple print just to show if a function was called.
print("MyFunction was called")

-- Printing numbers
print("Current sanity value: "..inst.components.sanity.current)

-- Printing booleans. To print booleans (true/false) you MUST wrap the boolean in a tostring() call,
-- to tell LUA to convert it to a string.
-- Example 1:
print("My value is higher than 100: "..tostring(myvalue > 100))

-- Example 2:
local isMyFeatureOn = true
print("Feature is on: "..tostring(isMyFeatureOn))

You can really use print-statements to great advantage. If you're unsure why your mod isn't working, just slap in print-statements in all the functions and have them print out "<function name> was called", and follow the trail in the log and your code side-by-side. Add in some extra print-statements to make sure your variables are set to what you expect, and I can almost guarantee you, that you will find out what is going wrong.

 

Posting A Topic

If you need help, post a topic in the appropriate modding section of the forum. Note that there is one for DS and one for DST. Please include the relevant code (Lua file) and an error log if you have an error (see above how to find the logs).

Try to keep your post on topic and don't ask too many things at once. It's better to start two, three or four topics, if you want help with two, three or four different things, but you should generally try to focus on fixing only a few things at a time.

Also, keep in mind that the people reading your post have zero knowledge of what you're doing, what you have working, what the context of the problem is, your file structure, how much you actually know what you're doing or anything at all, unless you inform them of it.

Remember that when you're new, the problem is often not what you think it is, but probably something "next to" what you think is the problem, so making sure that people know exactly what you're trying to achieve (the functionality you want to have in the end) and the context in which you're trying to achieve it (is the code for DS or DST? Is it in a bee or in the player?). And be specific. Ex: if you want a healing aura, what do you mean by that? Should the player be healed by being around some things or should things around the player be healed? Which things? What have you tried already?

And remember, stay positive ;)

Edited by Ultroman
had this erroneous post, so thought I'd move the newcomer post in here
  • Like 2
  • Big Ups 1

Share this post


Link to post
Share on other sites
Mick Satana    0

Thanks for listing these topics. It's really easy to follow.

 

ps, this link is broken.

On 3/10/2020 at 4:56 AM, Ultroman said:

Character item modding, special objects or features.

Share this post


Link to post
Share on other sites
Ultroman    717
18 hours ago, Mick Satana said:

Thanks for listing these topics. It's really easy to follow.

 

ps, this link is broken.

Thank you for the heads-up. Sadly, that post seems to have been deleted. I'm happy this list helped you :D

Share this post


Link to post
Share on other sites
Ultroman    717
On 7/14/2020 at 4:05 PM, Mick Satana said:

Thanks for listing these topics. It's really easy to follow.

 

ps, this link is broken.

That post has been replaced by this much more complete tutorial which includes exporting files to edit, converting them into separate images to edit using KTools and Spriter (I recommend that method, unless you really only need to do minor reskinning, as the author also says, but you'll probably want to get to know Spriter and KTools, anyway.

Share this post


Link to post
Share on other sites
Muskar    8
On 3/10/2020 at 1:42 AM, Ultroman said:

Normal modding forum search, when searching exclusively for DS or DST, but NOT BOTH:

 

Doesn't seem to work for me. I get the following result in both Chrome and Firefox - no button appears:

image.thumb.png.342beac3c35b65bf648e971b4a3eaed2.png

What am I doing wrong?

Also, perhaps in the Debugging section you could add a small section about writing out tables in runtime via a table serializer like serpent or others - noting licenses are worth keeping an eye on etc. I've only tried serpent but it helps greatly with the followings options:

 
local serpent = require "util/serpent" --put serpent.lua and license in "util" folder in the mod
--...
print(serpent.block(table, {metatostring=false, maxlevel=3, maxnum=50, nocode=true})) -- don't set maxlevel very high when metatostring is off, otherwise you'll likely run out of memory
 

 

Share this post


Link to post
Share on other sites
Ultroman    717
4 hours ago, Muskar said:

Doesn't seem to work for me. I get the following result in both Chrome and Firefox - no button appears:

image.thumb.png.342beac3c35b65bf648e971b4a3eaed2.png

What am I doing wrong?

It appears they've changed the script since I wrote that. Now you have to perform a search and press "More search options" to get to the list of forum sections. Fixed! Thanks for letting me know.

 

4 hours ago, Muskar said:

Also, perhaps in the Debugging section you could add a small section about writing out tables in runtime via a table serializer like serpent or others - noting licenses are worth keeping an eye on etc. I've only tried serpent but it helps greatly with the followings options:

 

local serpent = require "util/serpent" --put serpent.lua and license in "util" folder in the mod
--...
print(serpent.block(table, {metatostring=false, maxlevel=3, maxnum=50, nocode=true})) -- don't set maxlevel very high when metatostring is off, otherwise you'll likely run out of memory
 

 

I would love to, but I simply do not have the time right now. Also, I have never used any of those libraries. Never had the need. You seem like a bright fellow. I would urge you to write up a small tutorial / guide thread about using these, to help others and perhaps serve as a log of understandings for yourself in the future.

Edited by Ultroman
  • Like 1

Share this post


Link to post
Share on other sites

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