[AI] Introduction to AI Scripting

Status
Not open for further replies.
Level 6
Joined
Jun 16, 2004
Messages
237
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.

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

Cons:
- 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.


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

Pros:
+ 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)

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


Overall

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.

Cheers!
 
Status
Not open for further replies.
Top