Random map developer experience

Thanks heaps to the devs for keeping the random map scripting language fairly close to the original. I’m currently porting some of my old scripts to the new language and it’s a fairly straightforward translation.

Unfortunately they’ve also kept the terrible dev experience from the original, so I’d like to suggest some improvements. My workflow at the moment is that I have AOM open on one screen, and my code window open on another. I have AOM open to the map editor, and I run my script by creating a new map. I flip back and forth, making changes to my script and making new maps. Here are my suggestions:

1) New map dialog: Let’s start with a quick and easy one. The “new map” dialog should remember my settings, at least so long as the editor is open. Currently I have manually choose the level type from a long list, then set the player count and map size I want to test. It’s a little thing, but it gets annoying when I have to do this hundreds of times during script development.

2) Debug mode: The old AoM EE editor had a “debug mode” option for random map scripts. Now, this option was essentially useless, but it was a nice thought. My suggestions below would not be useful to most users, so it’d probably be a good idea to hide them behind a debug mode option. A checkbox in the “new map” dialog would be ideal.

3) Compile errors: This is by far the most important suggestion. If my script doesn’t compile, currently an error message pops up that just says the script failed to load. Compilers for any other language will tell you the line the error is on, and what the error is. If it’s too much effort to explain the error, at least just telling me the line number of the error would be a massive improvement. Otherwise I’m reading a 2000 line script trying to manually spot my mistake. I’ve literally had to resort to commenting out large chunks of the script to systematically narrow down where the error is. It slows down development on both ends, because I’m also hesitant to write more than a few lines of code before re-running the script, otherwise it gets too hard to figure out my mistakes.

4) Stack traces: If the script loads ok, but has an error during execution, the loading screen should print a stack trace of where the error happened (in debug mode). This is a bigger ask, but it should be possible since you guys presumably wrote the VM that runs the script. The old AoM EE scripts would just crash without telling you where. Again I had to resort to commenting out bits of the script. And if the crash was flaky, you’re screwed. On the plus side, script crashes seem to be way more rare in AoMR.

5) Print function: Not sure if this one exists and I just haven’t found it, but a print function would be super useful. It could print to a console that’s only visible in debug mode. I’d like to be able to print the value of variables, as well as just use it to trace control flow. If suggestion 4 is too hard, printing is a good fallback to narrow down where a crash is happening. rmEchoError etc look promising, but I can’t figure out where they’re supposed to be printing to. There’s no console, no popups, and no log files in my game folder.

6) Breaking changes: Please avoid breaking changes to the scripting language, and if you must publish a breaking change, include specific details in the patch notes (exactly what has changed, and how devs should adapt), or in a forum post or something. Ideally, some sort of proactive notification to mod devs (eg an in-game popup). I sat down to play my random map script tonight, and got the dreaded “failed to load” error. After 15 minutes of debugging (as mentioned before, I’m commenting out lines of code from a 2000 line script until it compiles, just to narrow down where the problem is), I found that the setRandomNatureCiv function no longer existed. After some sleuthing, turns out it was renamed to rmSetNatureCivFromCulture. This is a core function, so literally every random map mod was broken so that a function could be renamed. I couldn’t find any mention of this change in the patch notes. The few hundred people who have installed my mod also don’t really have a way of contacting me, so it’s literally just luck that I noticed, and I have no idea how long it was broken for. How many mods are going to languish in the store because their authors aren’t even aware they’re broken? There should be a very high bar to publishing breaking language changes, because the mod ecosystem relies on the good will of volunteer devs who probably aren’t manually testing their mods regularly. I can understand this sort of thing this early in the game’s life, but hopefully this becomes very rare as the game matures.

3 Likes

Re point 6, it’s usually possible to avoid breaking changes like the one I just experienced. For example, when you rename setRandomNatureCiv to rmSetNatureCivFromCulture, you can also add a setRandomNatureCiv function that looks identical to the original, but now just calls rmSetNatureCivFromCulture.

That way you get to do your rename, and all new scripts can use the new name, but you don’t break existing scripts that are still using the old one. Bonus points for marking the old API as deprecated.

It’s almost always possible to use tricks like this to avoid real breakages.

1 Like

Hi!

Regarding points 1-5 you can use debugRandomMaps in your user.cfg file to enable the simple XS debugger (which is now functional once again). Toggle it by setting a custom hotkey like map("yourhotkeyhere", "root", "gadgetToggle(\"XSDebugger\")") in your user.con file. Both files need to be created in your <user ID>/config directory if you haven’t done so already.

Regarding point 6: More recently, a community XS scripting discord has been launched to address your concerns regarding the update process and API compatibility, as well as general XS, RM, AI, and trigger questions: https://discord.gg/th6UB4ZRhs

2 Likes

For map development I often generate ingame instead of editor and I got a hotkey to reload the map making seeing changes quickly. I also have a hotkey to enter the editor during the game so you can load the game and then view in the editor. The hotkey for the editor is nice because it can free you from a softlocks where you get stuck on the map loading screen.

map (“alt-e”, “root”, “modeEnter("Editor")”)
map (“alt-e”, “game”, “modeEnter("Editor")”)
map (“alt-1”, “game”, “restartCurrentGame”)

You don’t have LOS but you can just add a trigger to turn off the fog and blackmap on game start or use the cheat code clear skies for a one off reveal.

these binds dont work for me somehow, its just launch editor during launching the game without pressing hotkeys