HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

AI & JASS FAQ

05-31-2003, 11:04 AM#16
AIAndy
Extract common.j and common.ai . In those you will find the declaration for all the natives. Natives are the base functions that are hard coded. The natives in common.ai can only be used from AI.
There are advanced functions in common.ai and Blizzard.j that call the natives and implement some better functionality. Blizzard.j cannot be accessed from AI.
When you search in this forum you can find a thread where many of the functions and natives in common.ai and their functionality are explained. More information on natives and JASS itself can be found on jass.sourceforge.net .
06-04-2003, 09:22 AM#17
Vidstige
I have great problems giving units order from an ai-script.

Could anyone show an example how an existing unit is
"addressed" and given an order.

In my script I would like to do something like this:

IssueImmediateOrder(whichUnit, orderString)

but how do I get hold of "whichUnit" which is of type unit?

I have read common.j and common.ai but I'm still confused. emote_confused
06-05-2003, 10:18 AM#18
PitzerMike
First of all you should have a local group and a local unit variable:

local group G = CreateGroup()
local unit U

Then use one of the GroupEnumUnits... functions from common.j. for example

call GroupEnumUnitsOfPlayer(G,Player(X),null)

Use null for the last parameter if you don't know how to use Filterfunctions and such. Next you use a loop to find the unit in the group you want

loop
set U = FirstOfGroup(G)
exitwhen U == null
exitwhen GetUnitTypeId(U) == 'hpea'
call GroupRemoveUnit(G,U)
endloop

In this example you would find a peasant owned by player X. then give your order:

if U != null then
call IssueImmediateOrder(U,"XXX")
endif
06-06-2003, 06:19 PM#19
Vidstige
Thanks Mike!

Now I am able to give my units commands from my ai-script. :D

Is there any possibility to put your own .j files in the map file and
call funtions in those files from either triggers or ai-scripts?

It seems less than optimal that I have to paste in my utility
functions everywhere... or is the solution to put the functions
in the maps own .j file?

/Vidstige
06-11-2003, 08:55 AM#20
Vidstige
Could anyone give me a hint on how filterfunctions work?

I would also be happy if anyone could hint me on how HarvestGold and HarvestLumber works. Should I call them repeatedly or just once? Some of my peasant seems to obey and some to ignore my command.
06-11-2003, 02:11 PM#21
AIAndy
You cannot include any other .j files so your only chance is to put your utility functions in the files that are already included. That would be common.ai for AI and Blizzard.j for trigger. You could try out common.j for both but i have never tried that.
Filterfunctions are functions that take nothing and return a boolean. They check a unit each time for specific criteria. You can turn any function that does that in a filterfunction with the function Filter. Does not work from AI.
Repeated uses of HarvestGold/Lumber add up the number of peons used on that. The AI takes from these peons to build so to send them back after building you should reset the Harvest AI and repeat your Harvest commands every few seconds.
06-12-2003, 03:52 AM#22
Guest
Quote:
Originally posted by AIAndy
You can turn any function that does that in a filterfunction with the function Filter. Does not work from AI.


Another thing I've had to discover the hard way. Is it true then that no callbacks at all are permitted in AI?

Looks that way and it stinks. I'm at a loss really to figure out how to achieve even a simple AI in a custom map unless the AI is going to build units and attack in the normal fashion...

e.g. I have 5 spawn points and 5 targets for units spawned from those points. I don't see how I can create a group specific to a set of units and issue orders to each one individually without using callbacks...

Any suggestions? CommanderAI doesn't do this sort of thing as far as I can tell but I haven't read the whole thing so slap me if I'm wrong there..!

Cheers
06-12-2003, 04:47 AM#23
Vidstige
Why not try something llike:
Code:
   local group grp = CreateGroup()
   local unit u
   call GroupEnumUnitsOfPlayer(grp,Player(GetAiPlayer()), null)
   set u = FirstOfGroup(grp)
   loop
      exitwhen u == null
      if GetUnitTypeId(u) == something then
         call IssuePointOrderLoc(u, "order", Location(x,y))
      endif
      call GroupRemoveUnit(grp, u)
      set u = FirstOfGroup(grp)
   endloop
But maybe you rather would use GroupEnumUnitsInRect instead.
06-16-2003, 01:17 PM#24
Vidstige
Is there any known problems with UnitId2String from ai?

It seems to choose strings from somewhere else, like "FoodAvail" when I am thinking more of "TownHall" feeding it with 'htow'. emote_sweat
06-16-2003, 06:04 PM#25
AIAndy
I think it is the same problem as with I2S. Returning strings from common.j natives to AI just does not work correctly.
06-16-2003, 10:17 PM#26
Guest
AIAndy,

I use your replacement Int2Str function and I have no need to worry about this for now. However when you investigated this originally, did you test whether the problem happens if you wrap the native commands in a local function?

I assume you did and the problem is more fundamental than a simple scope issue. If you don't know, then I can test it out. From experience, can anyone give me an example of something that fails? Like, does I2S always fail or just sometimes or ???

Cheers
06-17-2003, 02:53 AM#27
AIAndy
I2S always fails when used from any AI script. I found that out by trial and error when I first wanted to display some of the integers the natives return to find out more about them. My guess is that any native from common.j that takes code or returns strings does not work. It is a kind of a reference problem.
If you want to know more about the reason of this search for a post by Magnus99. He talked with someone from Blizzard about that.
06-17-2003, 05:37 AM#28
Guest
OK...looks like it's well and truly investigated then. That was a good thread to read... Lucky for me you've already made a good number of utility functions :)

Cheers
06-19-2003, 05:48 PM#29
Vidstige
When I train units (footmen), with SetProduce(1,'hfoo'), WC
sometimes crashes when the unit are just about ready to
enter the game world. :(

Have anyone got any thoughts on this? My script happily produces
tons of peasants, farms, lumbermills and towers; but somehow
sometimes when creating a footmen, it gets scary. Not always
though, after making some seemingly useless tweaking of got
it produced tons of footmen.

Could it be somekind of timing problem, I moved around some
statement and inserted a few short sleeps here and there and
then it seems to work...

Is there some known guidelines to follow regarding timing?
06-19-2003, 07:21 PM#30
AIAndy
I have never encountered crashes with SetProduce, but I have not used it that freely yet. Maybe you should post the code that is causing the problem.