News:

Simutrans.com Portal
Our Simutrans site. You can find everything about Simutrans from here.

squirrel script - build bridge/tunnel error: First click has side effects

Started by Andarix, August 11, 2026, 05:31:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andarix

This error has been occurring sporadically for some time now when the script AI is trying to build bridges.

The bridge is still built, however.

Now, this error also occurs when attempting to build a tunnel. This time, however, the tunnel is not built.

Simutrans r12138
pak64.german 0.124.4.0.1


victor_18993

Hi Andarix,
I've finished investigating the
First click has side effects issue, and the two reported cases are now understood and fixed in trunk.
They turned out to be two different
sqai_rail call-path edge cases that happened to trigger the same Script API guard:
  • Tunnel case: the tunnel tool was being called with two coordinates, but for surface tunnel construction the tool already acts on the first click. The Script API therefore correctly rejected the two-coordinate call. The fix is now using the one-position
    work(player, pos, param) form while keeping the tunnel descriptor.
  • Bridge case: the error occurred when the starting tile was already a bridge with the requested waytype. In that situation the normal two-click assumption no longer applies. The fix now skips that invalid tool call and lets the recovery logic already present in
    sqai_rail handle the route normally.
So this was not a Squirrel 3.2 regression, and the Script API guard itself is working correctly.
The fix has been integrated into trunk as r12172.
Validation performed before integration:
  • Squirrel syntax/import check: PASS
  • targeted tests: 3/3 PASS
  • full Simutrans regression suite: 286/286 PASS
  • 0 new assertions
  • 0 new script errors
One practical detail for tunnels: if the AI needs to know where the tunnel will emerge before building it,
tunnel_planner_x.find_end(...) can be used to obtain the calculated exit portal first.
Thanks for reporting it and for providing the screenshots and code paths — they made it much easier to isolate both cases.
Regards
En la vida todo son vivencias y cada una de ellas nos hace mas grandes,¿Como de grande eres tu? :)