So I decided I might actually post something more relevant
Full stops vs colons – continuing the above example, oUnit.GetUnitId() will return an error, but oUnit:GetUnitId() won’t.
It's maybe worth mentioning why that happens. oUnit:GetUnitId()
is syntactic sugar for oUnit.GetUnitId(self)
. So if you wanna you the version with .
you have to pass self
as first arg.
F9 opens up the debug window (you may want to change the game resolution to windowed to more easily access this).
That's a log window, not debug. You can open the debugger with Ctrl+F9 or /debug
and that's way better for debugging then trying to print things into the log. Since it works as any debugger you are used to, pauses the execution on the line you seleceted and lets you see whats inside global and local variables.
The below link also appears to give a list of core/global functions that can be used (I’ve not tested these to see if they all work, or even if they’re for FAF rather than SupCom2):
https://supcom.fandom.com/wiki/LUADOC_1.5.3599
It is for FA, some of these functions are documented here https://github.com/FAForever/fa/tree/deploy/fafdevelop/engine
I’m not using Github since I’m working on this on my own, and since I doubt I can get the same ease of use I currently have with changing something offline and instantly seeing the results in-game after a Ctrl+F10 restart. However, Github is used by a number of the AI developers so there’s likely some significant benefits to it.
Git is very useful even if you're working alone, as you have history of changes and you can easily switch to previous versions if something breaks. The game can use files from any location, so for my development, it uses files from my local git repo. It's just a matter of setting your own init file https://github.com/FAForever/fa#running-the-game-with-your-changes
To keep things simple (as I couldn’t get more complex builderconditions{} with multiple variables to work, despite seeing it being used in other AIs people have done)
So build conditions are defined in a table
BuildConditions = {
{BMBC, 'BaseEngineersEnabled', {self.BaseName}},
{BMBC, 'BaseBuildingEngineers', {self.BaseName}},
{BMBC, 'HighestFactoryLevel', {i, self.BaseName}},
{BMBC, 'FactoryCountAndNeed', {i, j, pType, self.BaseName}},
{BMBC, 'BaseActive', {self.BaseName}},
},
so here, you have 5 build conditions, each in it's own table.
local BMBC = '/lua/editor/BaseManagerBuildConditions.lua'
first value ( BMBC
) in the table is thr path the file you wanna use
second one ('BaseEngineersEnabled'
) is name of the function in that file to use
third ({self.BaseName}
) is table of arguments to pass into that function
AI brain is always passed as first argument, and then all other that you specify in the table
So you could rewrite your example to this:
-- Inside the builder
BuilderConditions = {
{MIBC, 'Is1NearbyMex', {11}}
},
-- Inside MiscBuildConditions.lua
function Is1NearbyMex(aiBrain, distance)
local iNearbyMex = MapInfo.RecordMexNearStartPosition(Utilities.GetAIBrainArmyNumber(aiBrain), distance, true)
if iNearbyMex == 1 then
return true
end
return false
end
This way you can already specify the distance for chehcking the nearby mexes.
Determine com start position
This function should do the trick
brain:GetArmyStartPos()
To help with this, I first wanted to understand what the various variables feeding into it were, so made use of the log function for each variable in turn; where it returned an error due to being a table value that I was trying to put into the log
Best would be to use the debugger to see whats what, as you can open the tables.
But if you really wanna dump the table into the log you have to use LOG(repr(table))