1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Must Have Campaign AI Programming Techniques

Discussion in 'JASS/AI Scripts Tutorials' started by Tommi Gustafsson, Jan 8, 2018.

Tags:
  1. Tommi Gustafsson

    Tommi Gustafsson

    Joined:
    May 26, 2017
    Messages:
    285
    Resources:
    6
    Tools:
    1
    Maps:
    2
    Tutorials:
    3
    Resources:
    6
    Hello!

    I was writing a couple of AIs for a Warcraft III Campaign, and came up some very important techniques that have not been discussed in any of the tutorials I've seen.

    1. Place your common AI code and globals to a custom common.ai

    If you are programming a lot of custom code for the AIs and not using Blizzard's functions in common.ai, you may end up writing all the way the same code into many AI files. I came up with a good technique to avoid that. Instead of writing duplicate code, you should place all your common code into a custom common.ai file.
    1. First, extract the original Scripts\common.ai from war3x.mpq
    2. Place it into your working directory and rename it to common2.ai (or whatever you like)
    3. Now, you may edit the common2.ai file as much as you like
    4. Place your custom globals into the globals sections at the start of the file
    5. Place your custom functions at the end of the file
    6. Then, import it into your campaign and set its path to Scripts\common.ai
    7. Now, Warcraft III loads your custom common.ai instead of the original file, and you get to share your code across all AI files and across all maps in the campaign.
    Very handy!

    2. Check AI errors with PJASS

    PJASS is an excellent tool to spot errors in your AI. When you are writing an AI, it is a tremendous help, if you can use it to spot all errors before importing your AI file to your map.
    1. Download pjass.exe from the above link. Be sure to get the latest version.
    2. Place pjass.exe into your working directory.
    3. Export common.j from war3x.mpq to your working directory.
    4. Place all your custom AI files into your working directory.
    5. Open Windows Powershell in your working directory (File Explorer -> File -> Open Windows PowerShell)
    6. Run .\pjass.exe .\common.j .\common2.ai .\custom.ai
    7. This checks both your common code in common2.ai and all your code in your custom.ai for errors (where custom.ai is the name of your custom ai file that you want to check for errors)
    Great! No more starting Warcraft III to check if you made any syntax errors in your AI file!

    Regards,
    Tommi
     
  2. Daffa the Mage

    Daffa the Mage

    Map Moderator

    Joined:
    Jan 30, 2013
    Messages:
    7,685
    Resources:
    27
    Packs:
    1
    Maps:
    8
    Spells:
    16
    Tutorials:
    2
    Resources:
    27
    There's another tool for syntax checking. Can't remember the name. No, it's not pJass.
     
  3. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,426
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Really useful trick! Thanks for sharing. Approved!
     
  4. Daffa the Mage

    Daffa the Mage

    Map Moderator

    Joined:
    Jan 30, 2013
    Messages:
    7,685
    Resources:
    27
    Packs:
    1
    Maps:
    8
    Spells:
    16
    Tutorials:
    2
    Resources:
    27
    JassDemo is a decent alternative for pJass, just sayin'

    Thanks for the useful informations though!