creatures caves welcome, guest
downloads   gallery   dev   community   creatchi   forum   mycaves
bookmarks | search | post new topic
Development Forum
A tale of two new CAOS editors   


  6/21/2020  5

** This post turned out long. So long story short, I wrote two CAOS editors over the last few weeks, one for JetBrains IDE's (not released) and one that can be used in a desktop browser (mobile does not work) **

Earlier in the year I was trying to get a handle on the OpenC2e source. Despite picking up Creatures 1 when it was new in the 90's, I never touched CAOS until a few months ago. I was confused by the documentation in the OpenC2e codebase, so I decided to become very familiar with CAOS especially for C1 as it is still my favorite. I couldn't really find a good C1 editor, so the only way to know if I understood it, was to inject the code and see if it crashed.

I used the DDE tutorial on (Which has been an amazing resource for me), and adapted it to C#. I created a simple program that would first run the CAOS 'sys: wrld [Eden.sfc]', wait a bit, then inject whatever command I wanted. I found though, that I made a lot of mistakes when writing code in a command string, so I thought I needed an editor.

I love JetBrains IDE's, and I use IntelliJ daily(for many hours a day), and Rider in bursts for weeks at a time. Having written language plugins in the past, I thought I would take a stab at writing another one, so I created a CAOS plugin for JetBrains IDE's.

When I write language plugins for JetBrains IDE's, I usually create two sets of Lexer/Parsers, one for the actual language and one for the definitions. I knew I needed to create the definitions, and also to make sense of the commands for use in the Lexer/Parsers, so I entered or parsed all commands from the C1 pdf, C2 word doc, and the html files for CV, C3, and DS. The last three were easy because the format was so regular, so I was able to write a script to pull data and enter it into my database. C1 and C2 were harder. I had to add it by hand, and also make sure I understood it correctly... especially C1. Man are those docs hard to follow. Some of it I could only make sense of due to the command being in C2 as well. In the database, commands are separate, and lvalue/rvalues share an entry. The database has 2,411 commands, though many are duplicate commands from other games especially the last 3. There are also 3,298 command parameters entered as well. I also entered in the chemical lists and some of the other value lists at the end of the doc. These are used for inlay hints.

I did all this for more than one reason. One was for the editor, but the other was because I was working on my own C# version of OpenC2e, and I could use the database to generate command stubs for all commands. Creating my own C2e codebase appears not to be necessary as when I got online today, it seems someone or some people are putting a lot of work back into OpenC2e already.

Still though having the commands in a database allowed me to format them however I wanted, and also to generate the lexer and parser with concrete elements for each command.

So with that I created the first CAOS editor for IntelliJ. It works pretty well, and has some nice features, like when you type 'setv clas' and then press alt+enter, it allows you to enter the family+genus+species, and it calculates the value for you. It also checks for command validity for both existence, use and correct game variant (ie. if you use EPAS in C1 or C2, it shows an error). It has popups showing you the arguments needed, autocomplete, and easy navigation to documentation. It validates type use, including inferring variable type so it can tell if the variable you used is holding an incompatible value.

I'm still polishing it, so it is not yet released, but it is exciting. I also gave an alt+enter action to split single line CAOS scripts into individual commands, and then to collapse it with spaces or commas after that. It indents C2+ enums and doif blocks, but does not do so for C1, as that seems to crash things.

It also has inlay hints to tell you what a number means if it has a corresponding list. If you type 'doif drv! eq 4', it will add an inline hint telling you what drive 4's name is in the current variant. Things like that. It might be too busy for some people, so the inlay hints can be disabled. Here is a screen shot from a CAOS script which alters the island carrot vendor to have it actually vend carrots.
screenshot of caos editor in IntelliJ IDE

I was happy with this IDE plugin, but I use a Mac, so I have to play Creatures on a windows virtual machine (I got so frustrated at one point, I actually bought a windows laptop simply to play on). I have tried running Creatures 1 in wine, and though the world loads, none of the applets work. Having read through the C1 CAOS documentation multiple times, I realized the Applets can mostly be recreated with CAOS commands. So I thought I just need a way to inject CAOS commands into the game, then I just need an interface.

This led me to writing a super-hacky dot-net program that launches Creatures in wine, and polls a subfolder for cos files, then injects them, writing the result to another subfolder. It worked, so I needed an editor to write CAOS scripts in to inject into the game using my convoluted DOTNet app. I looked into swift code editors, and saw that I can just embed a web editor into a Swift app, and then pull the code from the Webview, write it to a file, and then read in the result.

This meant I needed a web based code editor. I settled on Monaco, and used my database to generate a Lexer/Parser in Antlr. It worked out okay, but there were some kinks. So I remembered that when I was working on making my own fonts in high school, I read a book where the author had created a block of text she called Kern King, and it contained every letter combination in the english alphabet. I thought, I need something like that to check that all commands are in there. Again, I had the database, so I generated a script using every command, lvalue and rvalue for each variant, and plugged it into both editors. I found a number of errors, but things are looking good now.

The Monaco web version is not as feature rich. It has no variable type inference, but will check literal types. It has autocomplete and some popup descriptions, but no inlay hints or anything. I've tried to give it descriptive errors, instead of the crazy Antlr ones, but I may not have gotten them all. Still though, you can play with it.
Screenshot of a caos egg injection script written in the monaco web editor
Caos Chaos Web Editor

The two editors use very different colors. I think I like the Monaco one better, but will need to decide on colors before I submit the JetBrains plugin. I hope to do that in the next few days. It takes two days after submission though to get it approved and put into the IntelliJ plugin page.

As much as I love JetBrains IDE's, they are beasts, so I do not know if it would be worth downloading just to use the CAOS plugin. The app itself is 1 - 1.5 gigabytes (depending on edition), and mine runs averaging 1.5 to 2 gigabytes of memory at all times. I have 16 gigabytes of RAM which allows me to run IntelliJ, Rider, Unity and a windows 7 virtual machine at the same time, but I do not think that this is common. I love my iMac. It's 9 years old and runs beautifully... even if Apple won't allow me to download the last few versions of X-Code(those punks outmoded my machine.).

If you try out either of them (after they're both released), let me know what you thing. Especially let me know if they incorrectly report errors, or fail to notify you of one.



 visit Malkin's website: Malkin's page at CWiki
  6/21/2020  1

These look amazing! Have you considered adding a paste function to the web browser editor?

My TCR Norns



Wow, nice catch. I had no idea there was no paste button. I always use CMD+V on Mac and CTRL+V on Windows. I just read up on it, and I guess that only Internet Explorer allows a paste button in Monaco. Chrome allows paste after asking the user for permissions(so I added one), but Firefox denies the operation completely. I can understand why though. Sometimes people copy things they do not want read. I can definitely appreciate that. I do not have access to other browsers, so I do not know how they do.

Thanks for checking it out.



 visit Malkin's website: Malkin's page at CWiki

Thanks for checking that out for me. Paste works in Chrome. :)

My TCR Norns


  6/28/2020  1

I added a SPR viewer to the IntelliJ IDE plugin. I have decided I want to add a SPR compiler to the plugin, so I will not be releasing it until later. The viewer though allows you to view the sprites at different zoom levels, and check them against different colored backgrounds.

Here is a screenshot
Screenshot of Creatures 1 SPR file viewer in IntelliJ showcasing egg images at 4x zoom with a red background.


United States  


This is really exciting!

I didn't see this and released my own CAOS Tool. Want to combine forces somehow? Both of our tools are web-based (mine's electron) so we might could combine codebases, if you were interested in that of course.

Your grasp of language parsing seems stronger than mine, so I could probably learn a lot.


hack shack
script reservations
dev resources
active projects
dev forum
log in
lost pw
0 online
creatures caves is your #1 resource for the creatures artificial life game series: creatures, creatures 2, creatures 3, docking station, and the upcoming creatures family.

contact    help    privacy policy    terms & conditions    rules    donate    wiki