New Choicescript extension for VS Code (2.0 now runs games!)

I’ve released a new extension for VS Code, the popular programming text editor, that supports ChoiceScript. Along with syntax highlighting and auto-completing commands and variables, it shows common ChoiceScript errors as you write.

You can find everywhere that you’ve used a variable in your game and globally rename a variable.

It outlines your game, showing your choices, labels, and any *global or *temp variables.

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 want to add spell checking, install the Spell Right extension I modified to work with ChoiceScript.

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.

60 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.

4 Likes

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?

4 Likes

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.

2 Likes

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

4 Likes

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.

1 Like

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.

3 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.

4 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.

4 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”.

1 Like

After an embarrassing bit where I’d written way more than I thought I had, I updated the extension to add a word counter. It only counts words that the reader will see.

I also improved the outline to capture the individual options in a *choice.

Finally, it’s much better about finding problems in *if and *choice commands, especially the order of flags like *disable_reuse.

If you’ve installed the extension from the Marketplace, it should automatically update to version 1.4.0.

2 Likes

Okay, I’m ridiculously proud of a feature I finally took advantage of in VS Code that’s saved me a lot of work. In my current WIP, I’ve got characters who may be non-binary and use they/them pronouns. To deal with pronouns, I created a set of ${character_he} and {character_s} variables so I could write sentences like

${darcy_he} pick${darcy_s} up the book.

The problem is that I keep forgetting to include the _s variable.

Today I finally created a snippet so that when I type ${, one of the options is a template that auto-fills the _he and _s variables and lets me tab to the verb. If you want to try this yourself, follow the directions to create your own snippet and use the following snippet:

	"[Character] verb[s]": {
		"prefix": "${",
		"body": [
			"\\${${1:character}_he} ${2:verb}\\${${1:character}_s}"
		],
		"description": "[Character] verb[s]"
	}

8 Likes

hi! you do not know how much I needed this! thank you so much!! i’ll make sure to check for problems <3

2 Likes

I haven’t been posting updates here since recent ones have been bug fixes, but the latest version brings new capabilities to the table. Version 2.0 lets you run your in-progress game in a browser without your own copy of ChoiceScript, as well as run Quicktest and Randomtest against your game.

The new version adds an Open button to the left side of the bottom status bar when you’re in a game file. Press it to open your game in a browser.

Open Game button

Your game files are served live, so if you make changes to your game and want to reload, refresh the browser page. Any errors that are found get sent back to the editor and are annotated so you can see where the error occurred. If you close the browser tab with your game, press the Open button again. In fact, you’re free to press the Open button for as many browser tabs as you’d like.

To run Quicktest or Randomtest, right-click in the editor window and select the test you want from the context menu that pops up.

Context menu to run tests

Quicktest results appear in the Output window at the bottom of VS Code. If it finds an error, the error’s annotated in the same way that errors from running games are.

Example annotated error

Randomtest has a few extra steps. When you run Randomtest, VS Code will ask you to enter how many times to run Randomtest, your starting seed, whether to print your game’s text, and more. That can get tiring, so you can run Randomtest with default settings. To change those values, update the extension’s settings.

If you run Randomtest without it printing your game’s text, then the output goes in the same Output window as Quicktest. If, however, you have it print your game’s text, then the results appear in a separate editor window, just as if it were a regular file. You can scroll through it, and even save it to a text file if you want.

One small wrinkle: VS Code has a hard limit on the size of file it’ll let my extension open, and Randomtest can produce a lot of text. If Randomtest produces more than 20 MB of text, the extension saves the output to a file called Randomtext-[random id].txt in your game’s root folder. Even though VS Code won’t let me open that file, you can by double clicking it.

These are very new features, so please try them out and let me know how they work. I’ve stress tested them a fair amount on my game – the extension happily produced a 200 MB file from Randomtest, for example – but there’s bound to be issues.

10 Likes

Very neat! Thanks for sharing!

1 Like

So far I am absolutely loving this extension. I have been learning to code languages like C++ recently and it’s was really nice to code in Choicescript in Visual Studio Code. In fact, I am currently planning to completely switch from CSIDE to Visual Studio Code with this extension.

Although I had a pretty good experience with it so far, I have noticed that some of the features are missing from my installation.

First, the option to run the code in a browser is currently missing. I also made sure that the .txt file I was running was in the Choicescript file and that VSC recognized that I was coding in Choicescript.

And second, the option to quickest and randomtest the game in the context menu is also missing.

This honestly wasn’t a super huge deal though. The extension did the basics such as identifying errors in the code and highlighting commands. I just feel like that my experience with the extension could be better, is all.

Is there any particular reason as to why these features are absent in my installation? What should I do?

The extension’s loading, or else you wouldn’t get error notifications or the word counter at the bottom. To start with, I need some additional information.

  • What operating system are you using?
  • Could you take a screenshot of your installed extensions that includes the ChoiceScript Language one?
  • Could you give me a screenshot of your game layout (from the file explorer on the left)?
2 Likes

Sorry for the late reply. After I posted my problem here, I managed to get it fixed. All I had to do was simply open the Choicescript folder on the VSC file explorer, as you mentioned. After that, I managed to get the rest of the features working again. This was a pretty amateur mistake on my end, and I am sorry if I bothered you.

1 Like