{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreif6wdz6ycjfy6ksiidgwtgbpotib72wbcl4ixadaujr5y4j2rvcty",
"uri": "at://did:plc:i7budt2wflrcfy6jtvfocbix/app.bsky.feed.post/3mfnkklxp5rf2"
},
"path": "/viewtopic.php?p=1278256#p1278256",
"publishedAt": "2026-02-24T23:44:47.000Z",
"site": "https://www.tt-forums.net",
"tags": [
"Michiel"
],
"textContent": "> I managed to locally fix the \"arith op + on between 'null' and 'integer' crash.\n>\n> The problem is in builder_network.nut\n>\n>\n> Code:\n>\n>\n> function Run() {local tile;local count = 0;if (!subtasks) {while (true) {tile = RandomTile();SetConstructionSign(tile, this);if (AIMap.IsValidTile(tile) &&AITile.IsBuildableRectangle(tile - AIMap.GetTileIndex(Crossing.WIDTH, Crossing.WIDTH),Crossing.WIDTH*3, Crossing.WIDTH*3) &&EstimateNetworkStationCount(tile) >= 3) break;count++;if (count >= MAX_ATTEMPTS) {Warning(\"Tried \" + count + \" locations to start a new network, map may be full. Trying again tomorrow...\");throw TaskRetryException(TICKS_PER_DAY);} else {AIController.Sleep(1);}}AIRail.SetCurrentRailType(network.railType);subtasks = [LevelTerrain(this, tile, Rotation.ROT_0, [1, 1], [Crossing.WIDTH-2, Crossing.WIDTH-2], false),BuildCrossing(this, tile, network)];}RunSubtasks();// TOOD maybe preferentially expand in the direction farthest from the edge of the map?tasks.append(ExtendCrossing(null, tile, Direction.NE, network));tasks.append(ExtendCrossing(null, tile, Direction.SW, network));tasks.append(ExtendCrossing(null, tile, Direction.NW, network));tasks.append(ExtendCrossing(null, tile, Direction.SE, network));}\n>\n> The local variable tile happens to be null on a re-run of BuildNewNetwork task.\n> It initially has a valid tile, LevelTerrain and BuildCrossing subtasks are appended and then RunSubtasks() is called. But the AI finds itself waiting for money. When it re-runs this same task, local tile; makes it null. Since tile is only assigned with a value when there is no subtasks, all the ExtendCrossing will be passing a tile with a value of null. Somewhere else, when the ExtendCrossing task is run, this tile does an op + with a tile index diff but being null, it errors.\n>\n> I fixed by creating a member which I named network_tile in BuildNewNetwork class. The !subtasks block when called will set the value to this member. Now if the AI needs to wait for money, the ExtendCrossing will be using this.network_tile which has been set by the first run.\n>\n> Probably not the ideal way to fix this, but... it does the trick.\n\nIt's a fine fix! Thanks for the PR, I've adopted your fix into master. I'll try to make a new release soon.\n\nStatistics: Posted by Michiel — 24 Feb 2026 23:44\n\n* * *",
"title": "OpenTTD AIs and Game Scripts • Re: ChooChoo, a train network AI",
"updatedAt": "2026-02-24T23:44:47.000Z"
}