• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Custom AI stops working partway through map

Status
Not open for further replies.
Level 1
Joined
Mar 10, 2020
Messages
3
Hello all, this is my first post on hiveworkshop so bear with me.
I'm trying to create AI for a map i'm making with a simple JASS script, and controlling it through commands in the GUI.

Here is the section of the script that controls the attack behavior:

untitled-png.349241


And here is the trigger that tells that part to fire:
untitled2-png.349242


I have it set so that it picks a random player, and orders them to attack whenever the timer expires (messages are for debugging purposes).
The player's have been assigned to indices in an array, and the AI has already been initialized at game start. It all works how I intended, until I've destroyed about 4-5 out of 8 of the computer bases, then the remaining computers stop the attacking behavior. The recursive part works, and the messages are displayed, but the computer seems to not be receiving the AI command.

What am I doing wrong here?
(Please be basic, my understanding of JASS and programming is limited)
 
Level 12
Joined
Jun 15, 2016
Messages
472
I think Daffa is right on this one, and The AI could be assigning a dead payer to attack.

You can check if this is the problem using debugging messages inside the AI script, with DisplayTextToPlayer. If this is really the problem, you can solve it in a couple of ways:

1. If your decide a computer is dead if, for example, it has no builders, you can check if the player you're going to attack has builders using this function

JASS:
native GetPlayerUnitTypeCount takes player p, integer unitid            returns integer

just do something like set enemy_workers = GetPlayerUnitTypeCount(YOUR_PLAYER, PEON/PEASENT/WISP/...), and if you get 0, skip this player.

2. If you use a more complicated way to decide a computer player is dead, you really should do it with triggers in the map and send another command to the AI once an enemy computer is dead.

In case you choose the second way, and also if want to know more about how to use DisplayTextToPlayer, I suggest you read this tutorial on how to write and understand AI scripts.

Also, you might want to use DisplayTextToPlayer to show the number of the player you're attacking. in this case, paste this code at the start of your script, after the global variables:

JASS:
function Dig2Str takes integer i returns string
    if i == 1 then
        return "1"
    elseif i == 2 then
        return "2"
    elseif i == 3 then
        return "3"
    elseif i == 4 then
        return "4"
    elseif i == 5 then
        return "5"
    elseif i == 6 then
        return "6"
    elseif i == 7 then
        return "7"
    elseif i == 8 then
        return "8"
    elseif i == 9 then
        return "9"
    else
        return "0"
    endif
endfunction

function Int2Str takes integer ic returns string
    local string s = ""
    local integer i = ic
    local integer ialt = 0
    local boolean neg = false

    if i == 0 then
      return "0"
    endif
    if i < 0 then
      set neg = true
      set i = (-1)*i
    endif
    loop
      exitwhen i == 0
      set ialt = i
      set i = i / 10
      set s = Dig2Str( ialt - 10*i ) + s
    endloop
    if neg then
      set s = "-"+s
    endif
    return s
endfunction
// Courtesy of AIAndy and Tommi from http://www.hiveworkshop.com/threads/two-custom-campaign-ais-examples.8939/

then do something like this call DisplayTextToPlayer(USER, 0, 0, "want to attack player " + Int2Str(enemy_player)).

Last thing, if you have a question, feel free to reply here, and it would be better if you could next time post your triggers or AI script. How To Post Your Trigger
 
Level 1
Joined
Mar 10, 2020
Messages
3
Thanks for your replies, but I solved this one.
@Nowow Your tutorial was my starting point (and was very helpful by the way), so I went back and reread it, and it turns out I was missing a loop.
I misunderstood the way StartThread() worked and thought it would inherently loop because it was called in the main function.
 
Status
Not open for further replies.
Top