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.

[AI] Introduction to AI Scripting

Discussion in 'Triggers & Scripts' started by Tommi, Jul 20, 2004.

  1. Tommi


    Jun 16, 2004
    There are two ways of making AIs:
    • AI scripting (including AIs made in the AI editor)
    • triggers
    Both of them have advantages and disadvantages.

    AI Scripting
    Description: Looping scripts that can call functions in common.ai and common.j.

    + Building/training, rebuilding, expanding are rather straightforward (no control over exact building locations though)
    + Attacking is pretty simple

    - Supports only 1 attack group and 1 defense group
    - Little control over the attack & defense group (no direct functions to check which units are there etc.)
    - Can't remove units from the attack group (only when they die, they are removed)
    - Many functions don't work, such as ForGroup and string returning functions. Some workarounds exist. See the list here.

    Description: Event-based procedures that can call functions in Blizzard.j and common.j.

    + A great deal of control over units and their orders
    + Some high level actions, such as building, expanding, rebuilding, etc. not so easy to implement as in AI scripts. (Totally possible, though)

    - May be slower & CPU intensive than AI scripts, depending on their implementation
    - May require a lot of work


    AIs are best used for high level actions, such as building, expansion, etc., which would require a lot of trigger work. AIs can't respond immediately to events, since they are not event based.

    Triggers are best used for detailed actions and events, such as ordering a single unit to move to a location when a specific event happens. Also, triggers are the way to go, if you want more than one attack group per player.

    Combining AI scripts and Triggers

    You can combine AI scripts and triggers by using the AI - Send AI command trigger action, which is used to communicate between the AI and triggers. You can also communicate through functions that set and get non-string values in common.j (e.g. unit custom values and player properties). The AI script may check these values and adjust its behavior based on them. You can use the values sent through AI commands in the conditions of the AI editor. An AI script can also set some values (e.g. unit custom values or player properties) to communicate to triggers.