• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[AI] How to debug and get errors thrown by JASS AI?

Macielos

Hosted Project: W3E
Level 18
Joined
Jul 9, 2010
Messages
219
I've been experimenting with Jass AI for a while and while I managed to get some basic AI running, whenever I expand my test AI with new commands, I struggle to find causes of errors. When AI crashes or is invalid, there's no error message, debug functions like DisplayTextToPlayer are not called, AI just stops working and units do nothing, so I can only guess and comment out lines of script until I find a working version, then restore them, and so on.

So my question is: how do you handle this? What is the best practice here? Is there a way to call something like I'd write in OOP languages?
Code:
try {
  StartCampaignAI(Player(19), "myAI.ai")
} catch (e) {
  print(e)
}
I found a solution in LUA (pcall function) which works fine in my LUA scripts, but it doesn't seem to work with errors from StartCampaignAI() function.
 
Level 18
Joined
Mar 16, 2008
Messages
721
if it stops running but doesn't crash the game, that means it's stuck on some tech priority, or it doesn't have enough room to build something. i'd reccomend going through the tech priorities very carefully. or changing the terrain a bit.

you can have each function in the .ai script print a debug message but i didn't find that very helpful personally:
JASS:
globals
    player                  debug_player               = Player(4)
endglobals
JASS:
call DisplayTextToPlayer(debug_player, 0, 0, "25")
so this would display the text "25" in-game, to show you that the 25th function has been executed, i just numbered all the functions. this is barely useful because the crash will occur before the message is shown. and it's also hardly useful for finding what the .ai is hung up on if it doesn't crash, because these scripts seem to work by just spamming all the functions over and over.

as far as crash errors, those seem to be encrypted by blizz, so imo don't even waste ur time in that regard.

*edited
 
Last edited:

Macielos

Hosted Project: W3E
Level 18
Joined
Jul 9, 2010
Messages
219
Alright, after several more or less painful attempts I made a basic working AI for my custom faction. My thoughts so far:
  • You can't use sleep() anywhere in your script. e.g. for any delays between AI waves, it causes AI not to start with no errors. I learned it the hard way
  • My custom AI kept crashing when I attacked its base (not at first try though, probably after some initial units died). I think that giving it campaign defenders fixed the issue, but I'll be sure when I test it more
  • From the positives - I love DoCampaignFarms() option, makes AI build order so much shorter and more error-proof, no idea why it's not available through AI editor
  • Some other options are also useful, like GroupTimedLife()
 
Level 19
Joined
Jan 3, 2022
Messages
320
In case of the Lua engine, are you sure script errors don't leave anything in one of the game's log files? (in the documents folder)
You can't use sleep() anywhere in your script. e.g. for any delays between AI waves, it causes AI not to start with no errors.
Maybe sleep can only be used in functions that are resumed by the game, like Lua's yield. But we don't know which functions are made this way.
 
Top