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.

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

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]"
	}

4 Likes

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

1 Like

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.

9 Likes

Very neat! Thanks for sharing!

1 Like