Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.
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...
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...
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
local myarray=[];
foreach (town, population in wmTownList) {
foreach (town2, distance in wmTownList2) {
if (town == town2) {
myarray.push(town);
myarray.push(population);
myarray.push(distance);
}}}
lowindex to access them in the array will be myarray.len() * index
highindex will be lowindex+2;
Thanks for all your help. I ended up using the method Yexo suggested (generating one 'row' at a time and then stuffing it into the first array). My working code looks like this:
If you want to save some computation time you can skip generating half of the matrix as the distance from town A to B is equal to the distance from town B to A. However, when accessing the matrix you will need to make sure that A index is < B or the reverse depending on which part of the matrix you keep. So for tiny matrices as the example matrix it is probably just a waste of code complexity to only generate half matrices but for larger ones the memory + computation time saved can be significant. All depending on the problem size.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites) Junctioneer (a traffic intersection simulator)