Jump to content

Recommended Posts

Hello there, Computer science major here looking into getting more practice with scripting and programming.  I decided to start modding for don't starve together now that it's in early access.

 

I'm fairly fluent and reading and deciphering .lua's scripting language and I got a good idea on how it works.  But I'm looking to see if I can get some direction on some useful information that I in particularly need.  So I figured I'd ask a couple of questions to get on the right track.

 

1.  By looking at a function in a lua like inst.components.health.maxhealth I can figure out by the way it's written that it's adjusting a characters max health.  My question is, is there a library of these functions somewhere that I can reference when I want to use the right function for what I have in mind?  Perhaps I'm not using the correct terminology and that's why I haven't found it, but if anyone can inform me of such a reference that would be great.

 

2.  I intend to make some don't starve together playable characters, with that in mind if anyone has any tips on what I should or shouldn't do when making characters in the multiplayer setting

(I know that I probably should ask this in the don't starve together mod forum, but I noticed some of the things are similar for both sides.  For the multiplayer specific questions I'll ask there directly.)

 

3.  I never actually made a character in don't starve before, so I'm mostly using the examples listed in the tutorial and editing things to make things happen.  At the moment I just want to use a pre-existing character sprite (like wolfgang or wickerbottom) as a placeholder until I'm finished, then I'll have my artist friend work on the sprite but I seem to be having issues getting a pre-existing to actually show up in testing and I don't exactly know where I'm doing things wrong.  (Is there a good character tutorial for step by step?  if not I can manage, but I'd really like to know what each little thing does)

 

4.  I'm gonna be doing alot of testing in and out to make sure that what I'm scripting is actually working.  Is there a faster way of reloading my mods instead of restarting the game?

 

5.  Should I post this in the don't starve together forum instead?  I only really intend to make characters for the multiplayer version of the game so I'd assume that's where it's most relevant, but I don't know if there is anything on this forum that I could learn first.

 

Thank you in advance anyone who is willing to help me.

Do this first 

 

http://forums.kleientertainment.com/topic/46849-tutorial-using-extended-sample-character-template/

 

Work with Don't starve first.

 

I use gimp and paint.net for the artwork, mostly cause it's free

more gimp then paint.net, just because I like the format alot better.

 

Your going to work with a character template, If you deviate from it, you'll have to make minor adjustments.

In gimp, it's easier to select all, then select the float, then move it. But deviating too much will wreak havok.

 

After your done making the art, and messing with variables, that would be the time to research the next step.

but I would get the basics, and mess with them. first

Edited by RedRock911

Thank you for the very detailed and useful guide.

 

I understand jumping into don't starve together is ripe with alot of extra work and difficulties, but I intend to make these characters for me and my friends to use, so I'm going to be taking the hard route in getting this done.

 

I will however also make the characters on don't starve as well, but converting them over to don't starve together will be one of my main goals as well.

 

This template is doing a really great job of telling me what the parts of the character template do, but I'm still wondering if theres a list somewhere that states each function and what they do.  I'd like to consider all my resources so I can choose the best one for the job.

1.  There is no official API documentation currently There is some movement toward setting up unofficial documentation, though.  There's quite a way to go yet, but the discussion is at http://forums.kleientertainment.com/topic/49357-is-there-a-real-api-documentation/

 

See http://128.199.40.198/wordpress/ for current progress.  For now you're best off using the source files, probably.

 

Personally, I use File Locator Pro to search through *.lua to examples of functions in use, or to find the function definition. It's probably worth skimming through all of the relevant files to figure out how things work, and to get a sense of what methods and properties are available to entities and components. (See entityscript.lua for basic functionality that is shared among any character/item/object, for example)

 

I'd recommend using a text editor that has syntax highlighting and code folding, like Notepad++ or Sublime.  If you want a quick overview of all of the (non-anonymous) functions in a file, both of those programs make it easy.  In Notepad++, go to View -> Fold All.  In Sublime, go to Edit -> Code Folding -> Fold All.  If you want to inspect a function you can just hit the little +(or arrow, in Sublime) next to the line number on the left.

 

Keep in mind that there are still a handful of API functions that make calls to compiled code written in C++, and there is no documentation for those currently(though, I hear some official documentation is in the works).

 

2 and 3.  I can't help you there, sorry.

 

4.  AFAIK, no-- although you don't have to actually quit the game, you at least have to re-initialize it.  There's a few technical reasons why this is required and preferable.  Although there MAY be some way to reload the lua files and reinitialize the game, I haven't come across it.

 

For that reason, I do a lot of my testing in the console.  You can do pretty much anything that you could do within a mod within the console.  For example, adding a table to your character's entity is as simple as doing GetPlayer().sometable = { }.  If you want to get the reference to something in the world, you can use thing = TheInput:GetWorldEntityUnderMouse(), and then use the "thing" variable to mess around with it.  You can also get references to objects while you're spawning them using thing = c_spawn("someprefab").  Obviously you don't have to use the variable "thing" -- I normally use something that's 1 or 2 letters to stave off carpal tunnel syndrome.  You can test methods of objects in the console, and when you find something that works, put it into your mod.  Anything done in the console is done in the global namespace, though, so be wary of that. 

 

Finally, if you haven't already, though I can only imagine you have-- I would also recommend the "N Tools" mod-- it has a number of useful functions.  In particular it has the ability to dig through lua tables in game and to return their values, which is a great learning tool.

 

 

For that reason, I do a lot of my testing in the console.  You can do pretty much anything that you could do within a mod within the console.  For example, adding a table to your character's entity is as simple as doing GetPlayer().sometable = { }.  If you want to get the reference to something in the world, you can use thing = TheInput:GetWorldEntityUnderMouse(), and then use the "thing" variable to mess around with it.  You can also get references to objects while you're spawning them using thing = c_spawn("someprefab").  Obviously you don't have to use the variable "thing" -- I normally use something that's 1 or 2 letters to stave off carpal tunnel syndrome.  You can test methods of objects in the console, and when you find something that works, put it into your mod.  Anything done in the console is done in the global namespace, though, so be wary of that. 

 

Finally, if you haven't already, though I can only imagine you have-- I would also recommend the "N Tools" mod-- it has a number of useful functions.  In particular it has the ability to dig through lua tables in game and to return their values, which is a great learning tool.

Thank you for the awesome feedback, Guess I'll just have to figure most of it out and ask questions on the forum accordingly.

 

Yes I am aware of using the console for such things, I have called the debug function in don't starve together that summons a hound attack, so I've been able to fiddle around with that every so often.  I even found a way to calculate the amount of days before the next hound attack (That gonna be a feature for one of my characters)

 

From what you say does that mean I can essentially add features to characters on runtime to test how it runs?  Like for example would I be able to run a console command that can make my character treated as a monster, or add health regeneration?  That would save me alot of restarting to test features.  Unless I misunderstood what you were meaning.

 

The N Tools mod sounds like a great idea, I'll be sure to read into that and check out what it has to offer.

 

 Like for example would I be able to run a console command that can make my character treated as a monster, or add health regeneration?

 

You sure can! Don't think of it as a console, really -- it's just an interface to a lua thread.  You can override methods, use any global functions(or really any function that you can get a reference to, which is why it's useful sometimes to store references to locally defined functions in tables), and do anything else that you could from code.  Irritatingly, paste doesn't work in the console, so you have to type out everything there... hooooweverrrrr....here's a workaround that I came up with that makes my life easier:

 

I put a script file(test.lua) inside the scripts folder of the mod I'm working on.  Somewhere in the mod(modmain.lua works fine) I define GLOBAL function called "test".  From inside that function, I call dofile, which immediately executes the script.  You can modify the script as much as you want and then when you're ready to test, from the console enter test().  Here's my implementation:

GLOBAL.test = function(filename)    local filename = filename or "test"    return GLOBAL.dofile("../mods/<MOD NAME HERE>/scripts/" .. filename .. ".lua")end

This defaults to test.lua, but if you want to use multiple scripts, you can just pass them as the parameter(without .lua, for convenience).

 

You can also return a value from your file-- so for example if your test.lua was:

print("I'm a string :D")return "I'm a string too! :D"

...from the console you could do print( test() ).

 

Again, keep in mind that anything done inside the test.lua script will be in GLOBAL namespace, so make sure never to override critical variables.

Okay cool, I got some really useful tools and I feel I can get some really neat stuff done.  Couple things have been bugging me though.

 

While I get a general idea of what things do and what they are, I have no idea what they are called.

 

Example: What is an inst, as in is it short for a word?  I see it used everywhere and I have a general idea on what it represents.  But it's really hard to search for information on it when I don't know what it fully stands for.  

Same thing with self, it's refering to the object thats calling it I'm guessing.  I have an idea on what they do and how I can use them.  But I would have a better understanding if I could trace it to where it all begins (Or at least as far back as I can)

 

I like to take things apart and see how they work from the ground up, that way I can consider all the different ways I can approach it.

 

It feels like something that I should be able to google fu, but unfortunately I came up empty, probably because I'm just unaware of the terminology for it.

inst is generally a variable that holds a reference to a specific instance of an object.  self, as you guessed, is a variable that is pretty much always used to refer to the object that's calling it.

 

I talked a little bit about that concept here: http://forums.kleientertainment.com/topic/49415-add-sun-immunity-effect-on-umbrellas-and-freeze-screen-help/#entry606132

 

Essentially, lua allows you to call object methods two ways--

object.method()orobject:method()

The first version isn't passing any arguments.  The second version however automatically passes a reference to object as the first argument.  If you use that version, your method should probably be defined to accept "self" as the first parameter.

 

A method attached to a tool that plants custom items for you might have an inst parameter because it's designed to accept other objects as arguments.  The plantable objects however will most likely have a deploy method which has a self parameter, because it doesn't make much sense for one pinecone to be planting a different pinecone.  It also saves you the hassle of creating/maintaining a reference to the parent object that is available in local scope.

 

 

Edit: Fixed some typos and awful grammar.  I feel slightly ashamed to admit that English is my native language.

Edited by Corrosive

inst is generally a variable that holds a reference to a specific instance of an object.  self, as you guessed, is a variable that is pretty much always used to refer to the object that's calling it.

 

I talked a little bit about that concept here: http://forums.kleientertainment.com/topic/49415-add-sun-immunity-effect-on-umbrellas-and-freeze-screen-help/#entry606132

 

Essentially, lua allows you to call object methods two ways--

object.method()orobject:method()

The first version isn't passing any arguments.  The second version however automatically passes a reference to object as the first argument.  If you use that version, your method should probably be defined to accept "self" as the first parameter.

 

A a method attached to a tool that planted custom items for you, might have an inst parameter because it's designed to accept other objects as arguments.  The plantable objects however will most likely have a deploy method which have a self parameter, because it doesn't make much sense for one pinecone to be planting a different pinecone.  It also saves you the hassle of creating/maintaining a reference to the parent object that is available in local scope.

You sir, just made everything make 10x more sense.  I thank you for that.

4.  AFAIK, no-- although you don't have to actually quit the game, you at least have to re-initialize it.  There's a few technical reasons why this is required and preferable.  Although there MAY be some way to reload the lua files and reinitialize the game, I haven't come across it.

Would you believe it, I just searched and found out that Cheerio posted the answer to my question in this thread

http://forums.kleientertainment.com/topic/28665-tips-for-scripts/

 

 

Tip #2: DebugKeys

Don't Starve has a ton of debug keys which are shortcuts to help development.  Two of the most useful keys are 'CTRL+R' which reloads all lua scripts and jumps to the main menu

 

Sure enough, I tested it and it reloads my LUA files.  If theres an error however I need to restart, but still it's a nice little tool to have.

One thing is for sure, I'm learning a lot of ways how not to make a character, but that's me, I could spend a good three weeks just messing with functions and components

With my past experiences in programming, I've learned that it's good to keep things clean and clear, because if you get to used to doing things a messy way, eventually you'll have a gigantic flood of messy code thats hard to fix.

 

So if theres an easier/better way of doing the things I want, I might as well learn and do just that.

I'm more of "let's break it and see what happens" kinda guy. I love getting into it, and just seeing what things do. Especially modding. Then, when i'm serious about one of my projects, I can fully appreciate why or why not something works in a particular way. More importantly, I can let other people know how to fix some issues they maybe having. It;s ussualy  something simple. Like a typo  :hypnotized:

 

 

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