External Publication
Visit Post

OpenTTD AIs and Game Scripts • Re: nasal demons in action

Transport Tycoon Forums - Index page [Unofficial] March 2, 2026
Source

I did a little test as follows and it appears copying an AIList is not by reference as documented, but by value:

Code:

function TestList() {local lst = AIList();lst.AddItem(0, 0);lst.AddItem(1, 1);lst.AddItem(2, 2);lst.AddItem(3, 3);lst.AddItem(4, 4);lst.AddItem(5, 5);lst.AddItem(6, 6);lst.AddItem(7, 7);local copy = AIList();copy.AddList(lst);lst.RemoveItem(0);Log.Info(lst.HasItem(0), lst.Count());foreach(item, v in lst) {Log.Info(item, v);}Log.Info(copy.HasItem(0), copy.Count());foreach(item, v in copy) {Log.Info(item, v);}}

Attached image is the result:

As you can see, the original list "lst" had item 0 removed, but the copy kept the item, however the docs HERE say this:

Postcondition The list to be added ('list') stays unmodified.

So what is going on?

Isn't copy by reference? if it is then how is it possible that the item being removed stayed in copy, it should have been removed right?

Is this just coincidence I shouldn't rely on? Please enlighten me.

Statistics: Posted by GoldMine — 02 Mar 2026 05:20


Discussion in the ATmosphere

Loading comments...