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

Scripting with Sublime

Recommended Posts

Cheerio    2,675
Sublime is a really fast multi-platform free text editor with a ton of useful features.  It's also the most popular editor used to write lua here at Klei.  This guide will give you an introduction to what I think are some of it's most useful features.  This is not an introduction to modding or scripting however I do hope that both beginning and expert modders might find this guide useful :-).

 

Setup:

1. Install Don't Starve for Windows, Mac or OSX.

2. Install Sublime.

3. Unzip dont_starve_sublime_project.zip to your 'dont_starve/mods' folder.

4. Launch Sublime and click on 'project->open_project' and open the 'dont_starve.sublime-project' file.

 

Sidebar

post-283016-0-82588300-1381468540_thumb.

The tree view on the left side is called the Sidebar.  If you don't see it, you can turn it on in the 'view->sidebar' menu option.  The sidebar lets you browse both the script files used in 'Don't Starve' as well as any script files from any mods you may have downloaded.  What I really like about the sidebar is how it opens files just by clicking them.

 

Goto Anything - Shortcut='CTRL+P'

post-283016-0-59230600-1381467795_thumb.

This dialog lets you search for files and preview their contents.  Once you start getting used to the filenames in the project, it becomes much faster to open them through this window.

 

Goto Line - Shortcut='CTRL+G'

post-283016-0-71015600-1381467803_thumb.

This dialog lets you jump to a line within a file.  This is really useful when scripting because whenever you have a script error, 'Don't Starve' tells you the file and line number.

 

Find - Shortcut='CTRL+F'

post-283016-0-95760200-1381468459_thumb.

This dialog lets you search the currently opened file for a given string and will outline anything that matches it. You can then press 'F3' to jump through each match.

 

Find in Files - Shortcut='CTRL+SHIFT+F'

post-283016-0-14521900-1381467815_thumb.

This dialog is similar to the 'Find...' dialog except it searches through all files.  Most development I do in 'Don't Starve' involves reusing and extending existing scripts, so this dialog becomes incredibly useful at finding what I'm looking for.

 

And that's it!  These are just a few of Sublime's features.  It has many others and a huge plugin development community.  If you do give it a try or if you have a different favorite ide, let me know.  I'm always looking for ways to write code faster/smater/better :-).

 

For more Sublime tutorials, check out Perfect Workflow in Sublime Text 2.

Share this post


Link to post
Share on other sites
Cheerio    2,675

This is pretty cool unfortunately sublime does cost some money after a bit.

 

I would suggest using notepad++ and windows grep as an alternative its not quite as easy but they work.

I bought a copy for my own use but I thought the trial was infinite, it just started nagging you after a while.  This is what it says on the website:

 

"There is currently no enforced time limit for the evaluation."

Share this post


Link to post
Share on other sites
Nycidian    31

I bought a copy for my own use but I thought the trial was infinite, it just started nagging you after a while.  This is what it says on the website:

 

"There is currently no enforced time limit for the evaluation."

 

Interesting, I might try it I just don't want to get hooked on something I can't afford.

Share this post


Link to post
Share on other sites
Malacath    121

Yep, trial doesn't end. And the occasional nagging is totally worth it for all the features you get.

I especially like the design which is so much more comfortable than any other editor I ever used. And I also like using "Ctrl"

+"LMB" to put a cursor multiple places in the code and type at each place at the same time.

So I can absolutely approve Cheerios post, get this program... now!

Share this post


Link to post
Share on other sites
Cheerio    2,675

This is a really good tutorial. Thanks for sharing @Cheerio.

 

Also note, the project only works while the game is installed in the default directory.

Really?  I made all the paths relative but maybe I overwrote them.  Let me take a look :)

Share this post


Link to post
Share on other sites

@Cheerio: This is what it looks like after I installed sublime and used the project file within the zip file provided.

 

I simply created a new project, just thought I would make that relevant in case other people ran into similar issues.

 

post-245691-0-57754100-1381509545_thumb.

Share this post


Link to post
Share on other sites
Cheerio    2,675

This is a really good tutorial. Thanks for sharing @Cheerio.

 

Also note, the project only works while the game is installed in the default directory.

I've re-uploaded a new project which uses relative paths.  Thanks for catching this!

Share this post


Link to post
Share on other sites

I've re-uploaded a new project which uses relative paths.  Thanks for catching this!

 

Sorry @Cheerio it still doesn't work. All it does is opens up like usual and then displays the relative paths, which leads to no where. I'm looking into it on my end to see if there is a fix for it.

Share this post


Link to post
Share on other sites
Cheerio    2,675

Sorry @Cheerio it still doesn't work. All it does is opens up like usual and then displays the relative paths, which leads to no where. I'm looking into it on my end to see if there is a fix for it.

Which os are you running?

Share this post


Link to post
Share on other sites

Which os are you running?

 

I'm running Windows 8, so the problem was on my side folder structure set up. I got it fixed by adding "follow_symlinks" : true, to the beginning of the mods folder.

Share this post


Link to post
Share on other sites
debugman18    1,113

I use Sublime on my Windows PC, but there is no Mac port yet. I'm currently using TextWrangler for Mac, is there an alternative more like Sublime? (I really, really like the ability to change the color scheme.)

Share this post


Link to post
Share on other sites
Cheerio    2,675

I use Sublime on my Windows PC, but there is no Mac port yet. I'm currently using TextWrangler for Mac, is there an alternative more like Sublime? (I really, really like the ability to change the color scheme.)

There's an osx version of Sublime available on their download page:

 

http://www.sublimetext.com/2

Share this post


Link to post
Share on other sites

Yea, I'm not understanding this. I've been trying to learn lua and it's confounding me. I thought this editor might help some by being able to see the sidebar and searching for things, etc. But I'm stuck just on the project file provided. I open it. It's just some paths, and I have nothing in my sidebar except that project file. What should I be doing to get everything to show up as shown in the tutorial? I'm on windows 7 x64

 

EDIT: Well I thought I figured out what I did wrong. I think I need to open this as a project and not a file. When I did, I had directories for mods and data/scripts in my sidebar, but they don't contain anything. Learning to code sure makes a semi-intelligent guy feel like a complete moron. What am I doing wrong?

Share this post


Link to post
Share on other sites
squeek    229

Yea, I'm not understanding this. I've been trying to learn lua and it's confounding me. I thought this editor might help some by being able to see the sidebar and searching for things, etc. But I'm stuck just on the project file provided. I open it. It's just some paths, and I have nothing in my sidebar except that project file. What should I be doing to get everything to show up as shown in the tutorial? I'm on windows 7 x64

 

EDIT: Well I thought I figured out what I did wrong. I think I need to open this as a project and not a file. When I did, I had directories for mods and data/scripts in my sidebar, but they don't contain anything. Learning to code sure makes a semi-intelligent guy feel like a complete moron. What am I doing wrong?

Where did you put the dont_starve.sublime-project file? It has to be inside dont_starve/mods, as the paths are relative.

Share this post


Link to post
Share on other sites
UnderwearApp    134

I had the same problem (relative paths did not work). Easiest solution I've found is to remove the folders in there, then go to Project>AddFolder and select your mods, scripts, DLC folder. This will place them in the project with the files like the tutorial has, allowing you to search through files, etc

Share this post


Link to post
Share on other sites
squeek    229

Yep. It's in there. Here's a screenshot of my mods folder, and one of what I get when I open Sublime with the folders in side bar expanded.

The dont_starve.sublime-project file itself needs to be directly inside the mods folder. You have it as dont_stave/mods/dont_starve_sublime_project/dont_starve.sublime-project when it should be dont_stave/mods/dont_stave.sublime-project.

But, as ProfFarnsworth said, it's really easy to recreate what the .sublime-project file does. I usually just drag & drop folders into the Sublime sidebar.

Share this post


Link to post
Share on other sites

Aha, Ok then. The tutorial at the beginning says to unzip it to the mods folder. When I do that, it puts the folder in the wrong place.. or maybe I misunderstood. Working now though. Thanks!

Share this post


Link to post
Share on other sites

for the OS X users open the dont_strave_sublime_project with a text editor , change the second path to "/Applications/Don't Starve/Don't Starve.app/Contents/Resources/Don't Starve.app/Contents/data/scripts" and just do the rest ...

Share this post


Link to post
Share on other sites