| 03-11-2010, 02:38 PM | #1 |
***Edited***** This is AI script and not Trigger script. Triggers are not allowed in it. **************** I've order my wisp to scout some chosen places. Whenever a wisp is dead, another will be chosen to do the scouting. Sometimes when a wisp is dead the next scout will be bugged by stand still at the base and not doing anything even though it is being ordered repeat to move to target location. From my test result, it keep looped within this few messages in sequence. It is as what i want it to do. when there is a bugged scout then get a new one, then go scouting and keep re ordering it to the destination. call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Debug Scout") call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Getting A scout") call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Scout Available") call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Go Scouting") call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Re Ordered") JASS:function ScoutSequence takes nothing returns nothing local group g = CreateGroup() local unit u = null local integer array scoutTarget local integer scoutTarget_Index = 0 local integer index = 0 local integer indexJ = 0 local integer loopPoint = 0 local boolean goalReached = false local integer array buggedScout local integer buggedScout_Index = 0 local boolean isBugged = false local real scoutX = 0 local real scoutY = 0 //set all scoutTarget to 99 so that it will not cause scouting of location "0" loop exitwhen index == Terrain_Index set scoutTarget [index] = 99 set index = index + 1 endloop //scout loop loop loop exitwhen gameTime > 30 //60 call Sleep(1) endloop //decide on where to scout set index = 0 loop exitwhen index == 9 //unscouted mine or if duration of scout passed 5 min duration will need to rescout if (gameTime - LastScouted [index]) >= 60 or not Scouted [index] then //300 //only mine unowned need to be scout if TerrainCondition [index] == "Creep" or TerrainCondition [index] == "Cleared" then //expansion scout start after 10min of the game if index == 0 or index == 1 or index == 2 or index == 3 then call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, TerrainCondition [index]) set scoutTarget [scoutTarget_Index] = index set scoutTarget_Index = scoutTarget_Index + 1 else if gameTime >= 600 then set scoutTarget [scoutTarget_Index] = index set scoutTarget_Index = scoutTarget_Index + 1 endif endif endif endif set index = index + 1 endloop if scoutTarget_Index > 0 then //perform scouting set index = 0 loop exitwhen index == scoutTarget_Index //elect a scout if don't have scout if not UnitAlive(scout) then set scout = null endif loop exitwhen scout != null if GetUnitCountDone(WISP) > (c_mines_done * 5) then //c_mines_done * 5 + 5 if GetUnitCountDone(WISP) <= buggedScout_Index then set buggedScout_Index = 0 endif call GroupEnumUnitsOfPlayer(g,Player(MyID),null) call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Getting A scout") loop exitwhen scout != null set u = FirstOfGroup(g) exitwhen u == null if GetUnitTypeId(u) == WISP then set indexJ = 0 set isBugged = false loop exitwhen indexJ == buggedScout_Index if GetUnitUserData(u) != buggedScout [indexJ] then set isBugged = true endif set indexJ = indexJ + 1 endloop if not isBugged then call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Scout Available") call RemoveGuardPosition(u) set scout = u endif endif call GroupRemoveUnit(g,u) endloop set u = null call GroupClear(g) endif call Sleep(1) endloop call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Go Scouting") //perform scouting call Sleep(0.1) call IssuePointOrder(scout,"move",PointX [scoutTarget [index]], PointY [scoutTarget [index]]) set loopPoint = 0 loop exitwhen not UnitAlive(scout) exitwhen scout == null exitwhen goalReached if Modulo(loopPoint,10) == 0 then //check for bugged scout (unmovable) if scoutX != GetUnitX(scout) or scoutY != GetUnitY(scout) then set scoutX = GetUnitX(scout) set scoutY = GetUnitY(scout) call IssuePointOrder(scout,"move",PointX [scoutTarget [index]], PointY [scoutTarget [index]]) call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Re Ordered") else //debug it by finding another scout set scoutX=0 set scoutY=0 if scout != null then set buggedScout [buggedScout_Index] = GetUnitUserData(scout) set buggedScout_Index = buggedScout_Index + 1 call RecycleGuardPosition(scout) call Sleep(0.5) set scout = null call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Debug Scout") endif endif endif if gameTime - LastScouted [scoutTarget [index]] < 60 and Scouted [scoutTarget [index]] then //300 set goalReached = true endif set loopPoint = loopPoint + 1 call Sleep(0.5) endloop if goalReached then call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Scout Mission Completed") set index = index + 1 set goalReached = false endif endloop //clear targets for rescout set index = 0 loop exitwhen index == scoutTarget_Index set scoutTarget [index] = 99 set index = index + 1 endloop set scoutTarget_Index = 0 call RecycleGuardPosition(scout) endif call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Scouting Done") call Sleep(1) endloop endfunction |
| 03-11-2010, 03:17 PM | #2 | |||
Quote:
What is this? I'm assuming its some sort of call to TriggerSleepAction which is probably why your shit isn't working. Quote:
Yea, you can't do TriggerSleepAction in a loop and expect the loop to function properly, no matter what you rename the function to. Quote:
*Laughs even more* |
| 03-11-2010, 03:42 PM | #3 |
Ok i think i forget to clarify it. It is not Trigger script but ai script. calling sleep within loop is how normal pausing technique used in many other programming languages to temporarily pause the thread from continue doing anything. The script is working as it can display all my messages and only problem is the wisp is stuck for no reason after a few is dead. Early suspect is that it chosen the wisp that is transforming itself to ancients but then i've also write some debug codes which checks if the wisp is not moving at all then switch it and register that wisp as bugged. all bugged wisp will be reconsider once the total of bugged wisp registered is more than what the AI currently have. |
| 03-11-2010, 03:52 PM | #4 | |
I'm really not familiar with AI scripts. Quote:
JASS is not a normal programming language, and just because they have something like this in other programming languages doesn't mean it will function properly in WarCraft III. In fact, (again, I don't know much about AI scripts) using TriggerSleepAction actually causes a lot of bugs. I just opened up the common.ai file, and I guess their sleep function is not associated with TriggerSleepAction. JASS:native Sleep takes real seconds returns nothing |
| 03-11-2010, 05:29 PM | #5 |
for your information, there isn't any syntax error within the code i post. if there is a single syntax error it will cause either the game to crash or the thread that runs the script being destroy. The code is running and i can't find any logical error yet so i post it up to see if anyone found what is the problem. The scout loop which is an unlimited loop is to do this 1. check if game already passed for a specific amount of time. 2. store all location that wish to be scouted. 3. when there is location needed to be scout then get a scout. 4. if wisp is not registered as bugged wisp then it will be selected as scout 5. scout the specific location base on those stored in scoutTarget array. 6. every 5 second re-order the scout to move to the destination. *debug* check whether the wisp is still in same location, if it is then mark as bugged wisp and then select new scout (go to step 4). 7. when scout reach the destination it will then go to next destination. 8. whenever the scout is dead or null then get a new scout (go to step 4). 9. until all location is scouted then the scout is to be retired until new mission is given. |
