[Solved] Jass AI not working

Status
Not open for further replies.
So I have some experience with coding in Python and a little experience with other languages but this is my first time using Jass so I'm not clued up on some of the intricacies or details for how to code in it however I created this AI for one of my campaign maps but it doesn't seem to run at all and was wondering if you could help me out. The Defender units are all already pre-placed in the map along with the buildings.

JASS:
//Purple Forsaken Mission 2
globals
    player MyVictim = Player(1) //player 2 blue
endglobals

function main takes nothing returns nothing
    call CampaignAI('h606',null)
    call DoCampaignFarms(false)
   
    //Building Strategy
    //Tier 1
    call SetBuildUnit(1,'h602')
    call SetBuildUnit(5,'h603')
    call SetBuildUnit(2,'h608')
    call SetBuildUnit(6,'h606')
    call SetBuildUnit(1,'h607')
    call SetBuildUnit(1,'h609')
    //Tier 2
    call SetBuildUnit(1,'h604')
    call SetBuildUnit(1,'h60B')
    call SetBuildUnit(1,'h60A')
    //Tier 3
    call SetBuildUnit(1,'h605')
    call SetBuildUnit(2,'h60C')
    call SetBuildUnit(3,'h60D')
    //Defender Units
    call CampaignDefender(5,'ugho')
    call CampaignDefender(3,'uabo')
    call CampaignDefender(5,'uban')
    call CampaignDefender(4,'u600')
    call CampaignDefender(5,'n600')
    call CampaignDefender(6,'h601')
    call CampaignDefender(1,'u604')
   
    call WaitForSignal()

    //Attack Waves

    //Wave 1
    call InitAssaultGroup()
    call CampaignAttacker(4,'ugho')
    call CampaignAttacker(2,'n600')
    call CampaignAttacker(1,'U605')
    call SuicideOnPlayer(M3,MyVictim)
   
    loop
        //Wave 2
        call InitAssaultGroup()
        call CampaignAttacker(2,'h601')
        call CampaignAttacker(2,'u600')
        call CampaignAttacker(1,'u604')
        call SuicideOnPlayer(M4,MyVictim)
       
        //Wave 3
        call InitAssaultGroup()
        call CampaignAttacker(4,'ugho')
        call CampaignAttacker(2,'uban')
        call CampaignAttacker(2,'u600')
        call CampaignAttacker(1,'u604')
        call SuicideOnPlayer(M3,MyVictim)
       
        //Wave 4
        call InitAssaultGroup()
        call CampaignAttacker(4,'ugho')
        call CampaignAttacker(3,'n600')
        call CampaignAttacker(3,'u600')
        call CampaignAttacker(1,'U605')
        call SuicideOnPlayer(M4,MyVictim)
       
        //Wave 5
        call InitAssaultGroup()
        call CampaignAttacker(1,'uabo')
        call CampaignAttacker(4,'n600')
        call CampaignAttacker(2,'h601')
        call CampaignAttacker(1,'uobs')
        call SuicideOnPlayer(M3,MyVictim)
       
    endloop
endfunction
 

Attachments

  • upload_2020-4-25_17-41-55.png
    upload_2020-4-25_17-41-55.png
    125.2 KB · Views: 39
  • upload_2020-4-25_17-42-18.png
    upload_2020-4-25_17-42-18.png
    127.1 KB · Views: 53
Last edited:
Level 12
Joined
Jan 30, 2020
Messages
875
I have virtually 0 knowledge on AI, so sorry this post is not to answer your question but just to do a recommendation :

Please don't post screenshots of your code, try to use the 2 BBCodes available: [code=jass][/code] and [icode=jass] for the inline version.

It will make it much easier for people to read your code and help you.

Thank you and good luck with your AI problem.
 
Level 30
Joined
Feb 18, 2014
Messages
3,623
ai-script-png.353271

As you can see, CampaignDefender and CampaignAttacker are missing an argument which is Level (Difficulty) it should be like this instead :

call CampaignDefender(EASY, 1, 'ugho')
call CampaignAttacker(EASY, 2, 'ugho')

By the way, it will be much better to use constants instead of rawcodes to make things a lot more easier.
JASS:
globals
    player MyVictim = Player(1) //player 2 blue
   
    constant integer Forsaken_Ghoul = 'ugho'
    constant integer Forsaken_Archer = 'n600'
    constant integer Forsaken_Catapult = 'U605'
// etc
 

Attachments

  • AI Script.png
    AI Script.png
    70.9 KB · Views: 134
ai-script-png.353271

As you can see, CampaignDefender and CampaignAttacker are missing an argument which is Level (Difficulty) it should be like this instead :

call CampaignDefender(EASY, 1, 'ugho')
call CampaignAttacker(EASY, 2, 'ugho')

By the way, it will be much better to use constants instead of rawcodes to make things a lot more easier.
JASS:
globals
    player MyVictim = Player(1) //player 2 blue
  
    constant integer Forsaken_Ghoul = 'ugho'
    constant integer Forsaken_Archer = 'n600'
    constant integer Forsaken_Catapult = 'U605'
// etc

Thanks a lot i looked up the arguments and didnt notice that, do you know what the default difficulty in a campaign is? I'm assuming its Normal.

Thanks for also showing how to declare constants in JASS, whilst i have coding experience i dont know how similar the likes of python is to it.
 
Level 30
Joined
Feb 18, 2014
Messages
3,623
Thanks a lot i looked up the arguments and didnt notice that, do you know what the default difficulty in a campaign is? I'm assuming its Normal.

Thanks for also showing how to declare constants in JASS, whilst i have coding experience i dont know how similar the likes of python is to it.
Normal I guess. However, if your campaign has a variable difficulty you should use CampaignDefenderEx and CampaignAttackerEx instead. Example :

call CampaignDefenderEx(1,2,3, FOOTMAN)

Easy = 1 footman
Normal = 2 footmen
Hard = 3 footmen
 
Status
Not open for further replies.
Top