Defold Kit — Visual Studio Code Extension

:+1: This is a spiritual successor to the original guide How to turn Visual Studio Code into Defold IDE.

Version MIT License Website Mastodon Twitter Telegram Buy me a coffee

icon

Defold Kit

:tada: This happened.

:clap: Yes, the old guide has been reborn as the extension for Visual Studio Code.

:clinking_glasses: Named Defold Kit.

:fire: It can do everything that was described in the original guide. Automatically, with user-friendly installation and configuration.

:floppy_disk: You can install it from Visual Studio Marketplace.

:sparkles: And start to develop, build, launch, debug, bundle and deploy your game.

Features

  • :briefcase: Installing recommended extensions
  • :memo: Lua highlighting, autocompletion and linting
  • :hammer_and_wrench: Applying relevant settings to the workspace
  • :blue_book: Lua annotations for Defold API
  • :books: Lua annotations for dependencies
  • :rocket: Building and launching
  • :mag_right: Debugging with breakpoints
  • :package: Bundling for all the platforms
  • :calling: Deploying to connected mobile devices

Screenshots








Flexibility and Compatibility

  • It’s possible to uncheck all the options during Defold Kit setup and still be able to build and run the game using the Launch (without Debugger) command. But of course it’s much more fun to debug the game with breakpoints.

  • The extension can be used in combination with the Defold Buddy extension, which adds additional sugar and features. But don’t forget to clean up the API annotations to avoid duplication.

  • In the settings, you can choose which Defold API annotation source to use. Two options are currently available — astrochili/defold-annotations and mikatuo/defold-lua-annotations.

  • The extension doesn’t store any API annotations in the project folder, it uses the VS Code extension storage instead.

  • To use your own API annotations solution you can skip the Annotations Syncing step or run the Clean API Annotations command.

  • Tested on macOS and Windows, but should work on Linux as well. No bash scripts anymore (shell sessions with bob only :hugs:).

33 Likes

Wow, very impressive. Thank you for making this.

6 Likes

wow… Nice… If I have time will check on weekend

3 Likes

@astrochili I love this extension! thank you so much!

Just a question. When using VSC I do the following to test the game:
(1) press CMD-SHIFT-B and then
(2) select “Launch (without Debugger)”.

Is it possible to avoid the two steps and just have a single shortcut that does (1) and (2)? I am sorry for the maybe noob question…

Thank you so much!

EDIT: I have just noted that with (1) and (2) the project is not built but just the last build (made from the Defold editor) is launched. On the other hand if I try “Build to launch” then the build process is really slow. How may do in VSC something like CMD+B in the Defold Editor (that build and run in a second the game)?

Ciao!

1 Like

Hi @roccosaienz
I also used this extensions kit.

There are two options:

  1. [VS Code] Using F5 to run in debug mode
  • You have to add debugger script to the main collection.
  1. [Defold] Using F5 to run in debug mode.
  • You have nothing to do.

In the both option, you just need to press F5 button.
But I prefer to use option 2. Because the hot reload worked well.

For me, it seems hot reload doesn’t work when I run from vscode. It seems when run game from defold editor, there is a connection between running game & editor → editor can trigger hot reload.

Hope this help!

2 Likes

Hi @roccosaienz!

There are several ways to launch the game with Defold Kit.

Run and Debug (F5 by default)

This is the easiest way to run from VS Code. @uosdev mentioned the need to add a script, but it’s not really necessary. You only need a script in the project if you want to debug with breakpoints, otherwise the game will run without debugging (just like when you run a task). But it requires to install the local lua debugger extension and add the launch configuration during setup Defold Kit.

Key Binding

If you want to run without the local lua debugger (but there are not many reasons for this), you can add a shortcut to run the command. It’s possible to do from the command pallete (Ctrl/Cmd + Shift + P) or from the VS Code settings menu.


Add a task to the tasks.json file and set it as the default

It’s not currently possible, but the idea is a good one. Added an issue.

2 Likes

Regarding “create and run a game in a second”. Build in VS Code uses the bob builder with the “--variant debug build” arguments and it takes a bit longer than building in the Defold Editor.

Defold Editor uses bob too, but it uses some caching and change tracking approaches. This is a mystery to me and so I don’t know how to speed up the build process yet. Perhaps the Defold team could help with this and give some hints where to start.

If you need for a quick startup without debugging in VS Code and you don’t mind having an open Defold editor, you can just run the build in Defold. There is a Buddy extension to call the Build menu command in Defold Editor from VS Code, have a look at it.

5 Likes

Many many thanks to @uosdev and @astrochili.

I don’t mind having the Defold editor open in background (indeed I still need to use it for all the “graphical” editing of particles, collections, …). So the Buddy VSC extension to launch the game from VSC via the Defold editor should be perfect for me.

But may this extension conflict somehow with the Defold Kit? I am sorry, I know this is a very embarrassing question… I am lost with all these installation procedures…

Ciao.

2 Likes

But may this extension conflict somehow with the Defold Kit?

Haven’t tried it very closely, but it looks like the only overlapping functionality is syncing the API annotations. You can simply not use annotations syncing in Defold Kit. Or, on the contrary, do not use it in Buddy.

Otherwise you will have duplicate annotations. Buddy saves them to the project folder, Defold Kit to the extension storage folder.

2 Likes

I agree that it’s probably confusing. It’s good when there is a choice, but then which one to choose? Currently there are “Defold IDE” (old), “Defold Build Tools” (old?), “Defold Kit”, “Defold Buddy” with overlapping features between them. It would be great to have a single or a couple of “go to” extension when working with Defold in VSCode. However there is no easy way to combine the extensions since they are community extensions with each person having their own approach, goals, ideas and because it’s easier and more enjoying to work on your own stuff. I like the idea behind “Defold Build Tools” extension to have all building and running functionality in a single extension. I am also experimenting with debugging when game is started by Defold editor (not via Bob) and it makes sense to have that functionality outside of Buddy so that ppl who don’t use it still have access to debugging and stuff.

In example, that’s what I don’t like the most about Nunjucks templating language in VSCode is that there are a ton of extensions that do the same thing and I don’t know which one is the best.

2 Likes

2.0.5

Removed everything related the Launch (without debugger) and Build to Launch commands / tasks to avoid confusing users :stuck_out_tongue_winking_eye:

Now the only way to launch the game is using the Run ang Debug action.

This is also done so as not to provide functionality that can be done by other extensions - just run the game without debugging, but quickly.

3 Likes

It just seemed to me that your post raised a question about what all this is for, so I thought I’d respond in detail.

What’s up with the existing extensions?

I think that the significance of the intersection of features and the issue of choice is overstated.

  • I would not be wrong to say that Defold IDE has been unsupported for more than two years and is not up to date, since the only function it provides is refactoring hash constants.

  • Defold Build Tools has not been updated since 2021. It was created based on the guide, but originally as part of ts-defold. For lua users it can resolve dependencies, bundle and run with bob, but without debugger for lua, only TS.

  • With Buddy right now the only overlap is annotations, which there is no problem to disable. I’ve also added to the Defold Kit settings the ability to select your annotations.

Why did I create my own annotations generator?

Simply because I don’t know anything about C# or Java and I think it’s better to do these things in Lua so that everyone can fix things. I think it’s reasonable, it just works by this way.

Why did I create the extension?

Here are some criteria I follow:

  • Want to debug code in VS Code and to this day have the only working solution based on using lldebugger, bob and the algorithm described in the defold.sh script from the guide.
  • I want to run the game without running the Editor, if possible. I like to work with the engine as a framework and use the Editor more as a scene or gui editor.
  • I want to bundle and deploy the game to a connected mobile device without using the Editor.

If any of the existing extensions would have implemented this in the last two years, that would have been great. But that hasn’t happened, when personally that’s exactly what I need. So I implemented it in the expectation that someone else has the same approach and wishes.

Why didn’t I just add the functionality to Buddy?

  • I saw the original approach of communicating with the editor, not with bob, by design. But wanted to retain the ability to work without starting the Editor (described above why).
  • Responsibility for the guide, 100 stars keeps it from hiding, and I’m ready to continue maintaining.
  • I don’t have a heart for anything that mixes development and political views.

But this is my personal position, which may be close to a minority. And that’s not a problem, because the main fuel for me was the need for only the features I implemented. The only thing I’m missing now is smarter caching for the bob. But this is impossible to implement without a corresponding bob API that accepts a list of changed files to build.

Any file generators, refactoring, communicating with the editor over http - it’s just not my thing, there’s room for it and Buddy will do it well. If you implement debug via mobdebug that would be great, maybe I can use it too without running the Editor, why not.

5 Likes

Many thanks for your work to @astrochili @mikatuo . Now I am able to launch the game from VSC using Buddy and Defold: Project > Run.

However I see the console output in the Defold editor and not in VSC. But maybe this is unavoidable since Buddy is just launching the game in the Defold editor. And I’m getting a bit too picky… :slight_smile:

Ciao!

2 Likes

@astrochili You’ve made a great extension!

1 Like

Update: In the case of Defold Build Tools I was wrong. Just missed the point all this time and kept thinking that the extension funcionality is for ts-defold only. Just recently realised that launching with bob works with a regular project too, but without debugger for lua.

Thank you very much for this extension :pray: This is gonna save me a lot of time in the future

Quick question about annotations as its my first time using them. Ive got a module where i setup all the annotations but when i call a method within that module it does not show all the params etc but it does for the ‘new’ function within the module. I’ve attached 2 images of what I mean. Thanks in advance


Hello. As far as I can see, you have annotated the transitions class with the new method, which returns an new instance of transitions. But the start_transition method is a part of the instance table, not to the transitions class. So if you returns the transitions class then it’s okay that it doesn’t have methods of a table not related to the class.

But what exactly do you want to do, a module that creates instances of a class or something else?

Sorry for my very late response, I just never had the time to look more into the problem but on my xmas break I took some time to look at this again. I found the issue when I place line 6 above line 2 it works perfectly fine :slightly_smiling_face:

1 Like

It seems working great however I see that the build time on Visual Code is longer than on Defold

1 Like

Right. Unfortunaly, it’s not solvable at the moment without improving bob.

3 Likes