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.

Cheerio

Tips for Scripts

Recommended Posts

Cheerio    2,675
Here's a couple of tips for getting the most out of your Don't Starve scripting experience :-).  Please reply with your favorite tips and tricks :-).

 

Tip #1: ForceEnableMod

ForceEnableMod is a function you can call in 'modsettings.lua' which forces your mod to be loaded even if your mod crashed the game.  This means you don't have to keep going to the mods menu and enabling your mod.

 

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 and 'Right Shift' which jumps from the main menu right into game.  Debug keys can be enabled by adding the following lines to your 'modmain.lua' or by subscribing to this mod.



GLOBAL.CHEATS_ENABLED = true
GLOBAL.require( 'debugkeys' )


 

Tip #3: Use a good text editor

It doesn't matter if you use Visual Studio or Vim or Sublime, just please don't use notepad.  It was not meant to be used for scripting.  There are a ton of text editors which will save you a ton of time.  If you've never used any fancy text editors, you can follow this guide to get started with Sublime.

 

Tip #4: DebugSpawn

You can spawn any item/creature in the game by using the DebugSpawn command. When in game, bring up the debug console by pressing the '`' key.  Then try typing 'DebugSpawn(bat)'.

Share this post


Link to post
Share on other sites
Nycidian    31

I basically hack code so I am sure this will not be pretty but I though I would share how I search through the game process.
 
Basically when I want to find something out in the game if I can't find it in the lua files I start searching in the game itself. I do this by using two scripts
 

print(<variable>) 

Or

for key,value in pairs(<variable>) do print(key,value) end 

 
Use these in a function that you can control or that fire on load and you can see what is the value of a game variable
 
The first you use when its a single variable but sometimes it will return something that looks like table: 0B554048
 
This is where the second script come in handy as it will print out a table. For example say I wanted to know what all is under inst.components, I would use the following script (again in a function I can trigger such as the SimInit function in the modmain.lua file)
 

for key,value in pairs(inst.components) do print(key,value) end

This would give me a list of variables in the table and in this case more tables but now i can just add the variable with a table to the end of the last variable and rerun the script. it might be tedious and I'm sure there may be better ways but this allows me to search every thing in the game if I just know where to start.
 
Which by the way is GLOBAL which unfortunately has over 800 variables so you have to get creative.
 

local SpawnPrefab = GLOBAL.SpawnPrefablocal function spawnMulti(inst, n)if n >= 1 thenlocal prefab = SpawnPrefab("wetgoop")inst.components.inventory:GiveItem(prefab)return spawnMulti(inst, n-1)else endendfunction tablelength(T)local count = 0for _ in pairs(T) do count = count + 1 endreturn countend--Change variable in "tablelength(<variable>)" to explore the game files make sure you also change it below as well.local length = tablelength(GLOBAL)local c = 0function SimInit(inst)inst:ListenForEvent("oneatsomething", function(inst, data)local n = 0--Change variable in "pairs(<variable>)" to explore the game files make sure you also change it above as well.for key,value in pairs(GLOBAL) doif n >= c and n <= c +15 thenprint(n, key,value) endn = n +1if n == length thenc = c + 15endendend)spawnMulti(inst, 300)endAddSimPostInit(SimInit)

 

Here is a link to a mod for this function if anyone finds it useful

 

 

This mod will print out 15 variable on the GLOBAL variable for every time you eat something it also spawns you with 300 wet goop so you can easily control it. you can change the modmain.lua file to look at other variables as well.

Share this post


Link to post
Share on other sites
Malacath    121

I also like the little mod by simplex (I hope it's okay to mention it here, if not just tell me) which will give you a more controllable SpawnPrefab DebugSpawn function that let's you do funnny stuff like:

local pig = gimme("pigman")local merm = gimme("merm")pig.AnimStat:SetScale(3, 3, 3)merm.AnimStat:SetScale(3, 3, 3)merm.components.combat:SuggestTarget(pig)

Which wouldn't be possible with SpawnPrefab DebugSpawn

 

[...]
Basically when I want to find something out in the game if I can't find it in the lua files I start searching in the game itself. I do this by using two scripts

[...]

While it certainly works what your doing it is probably more helpful in most cases to search the script files for the variable or function you're interested in. Of course not manually, but any good editor hould allow you to search through lots of files.

Share this post


Link to post
Share on other sites
Nycidian    31

While it certainly works what your doing it is probably more helpful in most cases to search the script files for the variable or function you're interested in. Of course not manually, but any good editor hould allow you to search through lots of files.

Yes but that only works if those variables are in the lua that is exposed to us if its in the executables there is no searching for it. 

 

Also it if another way to look how things are put together sometime you know what variable you want to effect but you have no idea how to tell the game how to do it. This some times helps me figure out a way to tell the game what I want.

Share this post


Link to post
Share on other sites