TypeScreeps: Installing everything you need

This article assumes you are starting from scratch and will take you through the process from installing npm (a dependency manager) to the screeps-typescript-starter to actually pushing some code to the world of screeps. Feel free to jump ahead to whichever section best suites your needs.

Not yet sold on the idea of TypeScript? I’ve written an article that shows how it can be used in Screeps.

Installing Node.js

It is an exciting time to learn programming, when strangers can just give you a list of console commands to enter in a specific sequence and voila, you are good to go. Most of the time these will involve a package manager like npm, which is part of Node.js. We are going to use it to install some of the dependencies we need.

  1. Install nodejs.org.
  2. npm -v to verify installation (will show your version number).

Installing an IDE

An IDE (integrated development environment) isn’t strictly required, you could use any text editor. TypeScript really shines when you are using one. You might already have one that you prefer, and chances are there is a way to integrate typescript. If you’ve already done that, skip this section.

VSCode is an excellent and free solution, and this tutorial will use that. Other great alternatives that I’ve tried are Webstorm and Atom.

  1. Install VSCode.

Installing screeps-typescript-starter

The good folks who have contributed to the screeps-typescript-starter repository have already put together everything we need. For the purpose of this tutorial, I’ve made a fork with some minor adjustments, but feel free to get it straight from the source. One thing I’ve done is take out the testing suite and all the starter code in favor of something much simpler. I’ve also disabled linting from running by default.

  1. Download or clone screeps-typescript-starter repository (this is my fork).
    • git clone https://github.com/bonzaiferroni/screeps-typescript-starter.git
  2. Navigate to the folder and run npm install

This should install typescript and a lot of other dependencies, and it might take a while. You might get some warnings like these:

That’s ok, nobody knows what that means.

  1. Rename config/credentials.example.json to config/credentials.json and open it in an editor. Put your email and screeps password into the appropriate fields and make a mental note not to upload this file anywhere public (it is included in the .gitignore for that folder).
  2. The starter code assumes you have a branch called dev that exists on the server. This can easily be made by cloning an existing branch (see gif).

  1. If you are using a private server, you’ll want to make sure code is copied to the correct path. Open up config/config.local.ts and change localPath on line 14 to whatever value you need. (or use the symlink as suggested in the comment).

Writing some code and pushing to the server

Open up src/main.ts. You should see something like this:

export const loop = function() {
    console.log("hello world!");

That is the only thing currently running in your main loop. In my next article I’ll give some pointers on getting started with TypeScript. It is also intuitive to figure out on your own. If you already have a codebase, you could start by converting all your .js files to .ts files. They should already be valid TypeScript. Just start adding types as desired, and let the IDE be your guide. Also check out the official documentation, it is excellent.

Only thing left to do is push our code!

  1. npm run deploy to push your code to the Screeps.com server or npm run local to push your code to a local folder.

If you ran into any issues or questions, screeps slack chat is a good place to get some help. See the #typescript channel.

Share this post

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email