How do you create a 2D Array?
Posted: 07 Feb 2011 14:14
I've poured over the forum, the OpenTTD Wiki, and Squirrel documentation and can't find anything that works and the C++ method doesn't seem to work either. So how do you create a 2D array?? I expect this to work, but it doesn't...
Any suggestions?
What I'm attempting to do is create a 'table' with the distances between select towns. Here's the (non-working) code. Perhaps I just need another approach...
Many thanks in advance.
Code: Select all
WmAtlas [][] = array[WmTownList.Count()][WmTownList.Count()+1];
What I'm attempting to do is create a 'table' with the distances between select towns. Here's the (non-working) code. Perhaps I just need another approach...
Code: Select all
WmTownList = AITownList();
WmTownList.Valuate(AITown.GetPopulation);
local PopLimit = WmDOT.GetSetting("MinTownSize");
WmTownList.KeepAboveValue(PopLimit); // cuts under the pop limit
WmTownList.Sort(AIAbstractList.SORT_BY_VALUE, false);
AILog.Info(" Ignoring towns with population under " + PopLimit + ". " + WmTownList.Count() + " towns left.");
// Generate Distance Matrix
local iTown = WmTownList.Begin();
local WmTownList2 = WmTownList;
local jTown = WmTownList2.Begin();
// WmAtlas [][] = array[WmTownList.Count()][WmTownList.Count()+1];
// int WmAtlas [][];
for(local i=0; i < WmTownList.Count(); i++) {
WmAtlas[i][0] = iTown; // THIS IS WHERE IT BREAKS...
jTown = WmTownList2.Begin();
for (local j = 0; j < WmTownList.Count(); j++) {
WmAtlas[i][j+1]=AIMap.DistanceManhattan(AITown.GetLocation(iTown,jTown));
jTown = WmTownList2.Next();
}
iTown = WmTownList.Next();
}