New Choicescript extension for VS Code

I’ve released a new extension for VS Code, the popular programming text editor, that supports ChoiceScript. It auto-completes commands and variables, lets you find everywhere that you’ve used a variable in your game, does syntax highlighting, finds errors, and will let you rename variables across your whole game.

You can install it from the extensions Marketplace, or in VS Code, search for “ChoiceScript” in its extensions pane. You want the one labeled ChoiceScript Language, not the older ChoiceScript VSCode one.

If you run into any issues with it, please let me know!

And huge thanks to Kris Neidecker, who wrote the older extension and whose work I built on for this expanded extension.

16 Likes

Wow nice, I was about to start using VS Code for ChoiceScript and thought the older one was a little limited; this will be nice.

I’ll give it some try later and give feedback.

EDIT: I’m having some sort of issue. When using arrays I get a warning that it’s being used before it was created. I’m not sure if this is because it’s looking for a variable with the name “ally_slot” instead of an array named “ally_slot”. There’s another array named “enemy_slot” that is created on the bottom of my file that has the same warning.

Here are the files if you want to take a look and try. Keep in mind this is WIP code and it’s not yet runnable, but I think the warning is an issue with the variable detection itself.

1 Like

Whoops, I haven’t added support for arrays. So you’re exactly right: the indexer is indexing “ally_slot_1_1” and the like, and since it doesn’t recognize array syntax, it doesn’t know what to do with “ally_slot[1][1]”.

The best I can probably do is not flag references that use array notation at all, since the extension would need to keep track of the contents of variables to index them properly.

Did arrays ever get moved out of the experimental bucket?

1 Like

Afaik not. Not flagging arrays sounds pretty good of a solution to me. There shouldnt be manny independent arrays i think since they can have indexes to store as much stuff is needed.

I put together a version that better handles arrays that you can install locally. Please feel free to try it out.

1 Like

Seems to work fine, the arrays are not being flagged anymore.

1 Like

Heh, I was going to post about this extension. Glad I searched first.

Anyway, I think this with the Code Spell Checker extension should help folks have fewer code and spelling errors in their works.

I’ve just released version 1.1. It lets you find and rename labels and achievements. It’s also a lot better at flagging common errors, or at least the kind of errors I kept making until I made my extension flag it.

2 Likes

Version 1.2 is now available. The big addition is that, if you open the Explorer side panel (Ctrl-Shift-E), you can see the structure of your game in the Outline portion. It shows variables, choices, and labels.

I also greatly expanded error catching inside expressions that are part of *if and similar commands.

3 Likes

It turns out the spelling plugins don’t do well with ChoiceScript, so I modified the Spell Right plugin to handle ChoiceScript. Until the extension maintainer pulls in my code, you can download the extension as a .vsix file and install it locally.

3 Likes

@Sargent I have just started working with VS Code and your extension. I am seeing the following errors, which I don’t think are errors: “Variable ‘true’ not defined in this file or startup.txt” and the same with the word “false.” Since this is an underlying variable that is defined elsewhere. Looking in the startup.txt, it states the true/false variables are not defined in this file. How can we get this fixed?

Edit: I am noticing a few other errors that really shouldn’t be considered errors. For example, when I use *fake_choice, followed by *if - # …, *elseif - # …, *else - #, I get the error that states that the choice must be followed by # option or an *if, but when I run it in CSIDE, it works perfectly fine. Furthermore, when I use a single *if followed by three # choices, all indented at the same indentation, I get an error stating that the second and third # choices are indented too far; however, all three choices are only used if the *if condition has been met. CSIDE recognizes this as acceptable but it is an error in here. Why is that? What should I do if I see other “errors” such as these? Should I send a direct message to you or post them here? Am I doing something wrong in VS Code? By the way, I have your latest extensions of ChoiceScript Language and Spell Right, which is in the extension maintainer. I didn’t have to install it locally.

Also, why is it that I choose the word wrap option, then I click on a different scene and the word wrap option turns off? Do I have to manually turn it on for every scene?

You’re always welcome to send errors straight to me or post them here, whichever is easiest for you. The error flagging is very much new so I won’t be surprised if you found bugs.

I am seeing the following errors, which I don’t think are errors: “Variable ‘true’ not defined in this file or startup.txt” and the same with the word “false.” Since this is an underlying variable that is defined elsewhere.

That sounds like you’re using true where you should have a variable, as it’s not a variable but a value like 1 or "this is a string". Could you show me the code that it’s flagging? And does it run correctly through CSIDE?

Edit: I am noticing a few other errors that really shouldn’t be considered errors.

Can you show me them? I’m guessing especially the *fake_choice “error” is a mistake on my part.

Also, why is it that I choose the word wrap option, then I click on a different scene and the word wrap option turns off?

That’s something Visual Studio Code does, but you can change it. In VS Code, press Ctrl+Shift+P. That’ll bring up a bar near the top with a > in it. Type “Preferences” and then choose “Preferences: Open Settings” from the list. That’ll open the settings page. There’s a search box at the top. In there, type “Wrap” to bring up every option involving word wrap. Look for the “Editor: Word Wrap” option and change its drop-down box from “off” to “on”.