[AI] Custom AI script not working

Level 5
Joined
Oct 19, 2024
Messages
17
Hello. I have, as of late, been trying to make a custom AI script using JassCraft, but when I try to run it in the game, the AI completlely ignores the script, and does nothing.

I have followed two tutorials: The one Turnro made on YouTube, and the one made by Nonow, "Creating AI Workflow". I have not managed to make either of them work.
Here is the script that initialises the AI:

  • Events
    • Map initialization
  • Conditions
  • Actions
    • Player - Make Player 1 (red) treat Jugador 2 (azul) as an Enemigo
    • Player - Make Player 2 (blue) treat Player 1 (red) as an Enemigo
    • Player - Set name of Player 2 (blue) to Bonemauler Clan
    • IA - Start campaign AI script for Player 2 (bluel): war3mapImported\PruebaIAJASS.ai
    • IA - Send Jugador 2 (azul) the AI Command (1, 0)
    • Player - Set Player 2 (blue) current Gold to 50000
    • Player - Set Player 2 (blue) current Wood to 50000
Here is the first code I tried to make, using Turnro's tutorial:
JASS:
//------------------------------------------------
//              TEST
//------------------------------------------------

globals
    player user = PlayerEx(1)
    integer Tier = 1
endglobals   

//------------------------------------------------
//              MAIN
//------------------------------------------------

function main takes nothing returns nothing
    call CampaignAI(BURROW, null)
    call DoCampaignFarms(true)
    
    call SetHeroesFlee(false)
    call SetGroupsFlee(false)
    call SetReplacements(1, 2, 3)
    call SetSlowChopping(true)
    call SetPeonsRepair(true)
    
    call SetBuildingUnitEx(1, 1, 1, GREAT_HALL)
    call SetBuildingUnitEx(9, 9, 9, PEON)
    call SetBuildingUnitEx(1, 1, 2, ORC_BARRACKS)
    call SetBuildingUnitEx(1, 1, 1, FORGE)
    call SetBuildingUnitEx(3, 3, 4, GRUNT)
    call SetBuildingUnitEx(1, 2, 3, SHAMAN)
    call SetBuildingUnitEx(1, 1, 2, RAIDER)
    call SetBuildingUnitEx(1, 1, 1, PEON)
    
    call CampaignDefenderEx(3, 3, 4, GRUNT)
    call CampaignDefenderEx(1, 2, 3, SHAMAN)
    call CampaignDefenderEx(1, 1, 2, RAIDER)
    call CampaignDefenderEx(0, 0, 2, HEAD_HUNTER)
    
    call WaitForSignal()
    
    // WAVE 1
    
    call InitAssaultGroup()
    call CampaignAttackerEx(1, 2, 4, GRUNT)
    call SuicideOnPlayer(60, 60, 40, user)
    
    // WAVE 2
    
    call InitAssaultGroup()
    call CampaignAttackerEx(3, 3, 4, GRUNT)
    call CampaignAttackerEx(1, 1, 2, SHAMAN)
    call SuicideOnPlayer(60, 60, 40, user)
    
    loop
        call InitAssaultGroup()
        call CampaignAttackerEx(3, 3, 4, GRUNT)
        call CampaignAttackerEx(1, 1, 2, SHAMAN)
        call CampaignAttackerEx(0, 1, 1, RAIDER)
        call SuicideOnPlayer(90, 80, 70, user)
    endloop
endfunction

This code is not working for me, since the AI collects gold as normal and produces no units.

The second code, using Nonow's guide, is:
JASS:
//------------------------------------------------
//              TEST
//------------------------------------------------

globals
    player user = PlayerEx(1)
    integer tier = 1
endglobals


//------------------------------------------------
//              BUILD
//------------------------------------------------

function BuildOrder takes nothing returns nothing    
    call SetBuildingUnitEx(1, 1, 1, GREAT_HALL)
    call SetBuildingUnitEx(9, 9, 9, PEON)
    call SetBuildingUnitEx(1, 1, 2, ORC_BARRACKS)
    call SetBuildingUnitEx(1, 1, 1, FORGE)
    call SetBuildingUnitEx(5, 5, 5, BURROW)
    call SetBuildingUnitEx(3, 3, 4, GRUNT)
    
    if tier > 1 then
        call SetBuildingEx(1, 1, 1, STRONGHOLD)
        call SetBuildingEx(1, 1, 1, LODGE)
        call SetBuildingEx(1, 1, 1, BESTIARY)
        call SetBuildingUnitEx(1, 2, 3, SHAMAN)
        call SetBuildingUnitEx(1, 1, 2, RAIDER)
    endif
endfunction


//------------------------------------------------
//              CAMPAIGN DEFENSE
//------------------------------------------------

function Defenses takes nothing returns nothing
    if tier == 1 then
        call CampaignDefenderEx(3, 3, 4, GRUNT)
        call CampaignDefenderEx(0, 0, 2, HEAD_HUNTER)
    elseif tier == 2 then
        call CampaignDefenderEx(3, 3, 4, GRUNT)
        call CampaignDefenderEx(0, 0, 2, HEAD_HUNTER)
        call CampaignDefenderEx(1, 2, 3, SHAMAN)
        call CampaignDefenderEx(1, 1, 2, RAIDER)
    endif
endfunction
        
//------------------------------------------------
//              ATTACK
//------------------------------------------------

function Tier1Wave takes nothing returns nothing
    local integer AttackTier == tier
    loop 
        // WAVE 1
    
        call InitAssaultGroup()
        call CampaignAttackerEx(1, 2, 4, GRUNT)
        call SuicideOnPlayer(3M, 3M, 3M, user)
        exitwhen AttackTier != tier
    
        loop
            call InitAssaultGroup()
            call CampaignAttackerEx(3, 3, 4, GRUNT)
            call SuicideOnPlayer(3M, 3M, 3M, user)
            exitwhen AttackTier != tier
        endloop
        exitwhen AttackTier != tier
    endloop
endfunction
        
function Tier2Wave takes nothing returns nothing
    local integer AttackTier == tier
    loop 
        // WAVE 1
    
        call InitAssaultGroup()
        call CampaignAttackerEx(3, 3, 4, GRUNT)
        call CampaignAttackerEx(1, 1, 2, SHAMAN)
        call SuicideOnPlayer(3M, 3M, 3M, user)
        exitwhen AttackTier != tier
    
        loop
            call InitAssaultGroup()
            call CampaignAttackerEx(3, 3, 4, GRUNT)
            call CampaignAttackerEx(1, 1, 2, SHAMAN)
            call CampaignAttackerEx(0, 1, 1, RAIDER)
            call SuicideOnPlayer(3M, 3M, 3M, user)
            exitwhen AttackTier != tier
        endloop
        exitwhen AttackTier != tier
    endloop
endfunction

function AttackSwitch takes nothing returns nothing
    loop
        if tier == 1 then
            call Tier1Wave()
        elseif Tier == 2 then
            call Tier2Wave()
        else
           call DisplayTextToPlayer(user, 0, 0, "Something's not right")
        endif
    endloop
endfunction


//------------------------------------------------
//              COMMAND
//------------------------------------------------

function TierCondition takes nothing returns nothing
    if CommandsWaiting() > 0 then
        set tier = GetLastCommand()
        call PopLastCommand() 
        call InitBuildArray()
        call InitDefenseGroup() 
        call BuildOrder()
        call Defenses()
    endif
endfunction      

function ConditionLoop takes nothing returns nothing
    call TierCondition()
    call StaggerSleep(1, 5)
    loop
        call TierCondition()
        call Sleep(2)
    endloop
endfunction


//------------------------------------------------
//              MAIN
//------------------------------------------------

function main takes nothing returns nothing
    call CampaignAI(BURROW, null)
    call DoCampaignFarms(false)

    call BuildOrder()
    call CampaignDefenses()

    call StartThread(function ConditionLoop)
 
    call AttackSwitch()
endfunction

I haven't managed to make this code work, either. The AI still does nothing.

I have been using JassCraft to code, and as far as I am aware the shouldn't be any major syntax errors. If anyone could tell me what's wrong with the code I've written, it would be deeply appreciated.
 
Level 30
Joined
Aug 29, 2012
Messages
1,382
There are a few errors in the first script

1738333290002.png


The function is SetBuildUnitEx, not Building :) Similarly, if you use SuicideOnPlayer, you can only have 1 time frame, in your case you should be using SuicideOnPlayerEx to specify a time for each difficulty
 

Attachments

  • Test1.ai
    1.8 KB · Views: 2
Last edited:
Level 5
Joined
Oct 19, 2024
Messages
17
Thank you so much! I was going insane trying to find the mistake. I spent waaay too much time trying to figure it out.

However, may I ask which Syntax Checker is that? I currently use JassCraft, but it's clearly not enough to stop me from doing it wrong. I have looked around for a Syntax Checker for Jass, but most links I found were dead.
 
Top