OpenTTD AIs and Game Scripts • nasal demons in action
For those who don't know what nasal demons are it's when you get frustrated with strange program flow so much you start to blame compiler, and out of frustration demons start to go out of your nose. (you can google for details if you want)
I got frustrated because noticed squirrel doesn't let you copy AIList or tables. Actually you can copy them and your copy will be fine as long as original isn't modified, but as soon as you clear the source table or list your copy will no longer be a copy, data will be lost in both containers because for some unholy reason memory is somehow shared.
Even if you manually copy AIList with AddItem it's still not going to be an independent copy, this is the most stupid language feature I've ever seen, why the f I can't make a copy?
I found the only solution to make an independent copy of a container such that modifying the source leaves the copy alone is to create an array and extend it with data you want to copy. For instance:
Code:
local lst = [];local add = [];add.extend(lst); // I'm true independent copy
The "add" is now true copy, you can clear or modify "lst" but add will keep the copied data. You can even remove elements from lst but copy keeps the data.
Why can't this be done with AIList and tables? Why copying a list or table means having a copy that shares memory with source?
This is really silly. It took me unreasonable time to figure out what's happening.
Statistics: Posted by GoldMine — 28 Feb 2026 14:02
Discussion in the ATmosphere