Ammo Loader+


More than just a turret loader. Auto load everything from turrets to artillery wagons to furnaces and even the player themselves. Auto upgrade ammo and fuel without tedious manual replacement. Infinite range and compatible with Factorissimo2.

Content
4 months ago
0.14 - 2.0
26.4K
Logistics

g global Array use

5 months ago

global Array use

@Kux-CoreLib: A global class 'Array' already exists! dump:
{
objMT (table)
new (function @ ammo-loader/stdlib/Array.lua
insert (function @ ammo-loader/stdlib/Array.lua
remove (function @ ammo-loader/stdlib/Array.lua
removeValue (function @ ammo-loader/stdlib/Array.lua
removeIndex (function @ ammo-loader/stdlib/Array.lua
contains (function @ ammo-loader/stdlib/Array.lua
iter (function @ ammo-loader/stdlib/Array.lua
getIndex (function @ ammo-loader/stdlib/Array.lua
indexOf (function @ ammo-loader/stdlib/Array.lua
merge (function @ ammo-loader/stdlib/Array.lua
equals (function @ ammo-loader/stdlib/Array.lua
toHash (function @ ammo-loader/stdlib/Array.lua
fromHash (function @ ammo-loader/stdlib/Array.lua
}
Resolving mode: override

if you don't mind it being overwritten. you can just ignore it. i will remove the message from the log now.
if possible use local, this avoids such conflicts

4 months ago

Thanks for letting me know about this!

I admit I am a little confused however. According to the Factorio API docs:

each mod's control.lua file is loaded and executed in their own Lua state that will be owned by them for the remainder of the play session.

Also from the modding tutorial linked directly on the Factorio API home page:

During this stage, each mod's control.lua is run, in it's own lua instance (this means no inter-communication without special setup) which it will own for the rest of the play session.

Unless I am mistaken, that means that my global variables should not be accessible from outside my mod (unless I give access to them using the bootstrap API), correct? I also wonder why this is the only global that is causing problems, when I have many other global classes with very common names (util, Area, Queue, Map, etc.) that don't seem to be interfering.

I can swap to locals in this instance pretty easily, and will do so, but if you have time to give more insight into what is going on, I would deeply appreciate it! I'm always interested in learning more on the intricacies and best practices of Factorio and its modding API whenever I have the opportunity!

4 months ago
(updated 4 months ago)

yes in control stage all mods are isolated. but not in all other stages
and Array seems to be used everywhere.

BTW . if you define a global variable in data.lua alle mods can access this. the same variable is still available in data-update und data-final-fixes.
But you shouldn't rely on them not being overwritten by other mods between stages.
If you know this, you can use it to establish communication between mods. or you should redefine your own global variables in EVERY stage. I have gotten into the habit of using a single global variable with my mod name, which is not accidentally overwritten in the rule because the name is more or less unique.
_G["<your-mod-name>"].my_global var. is unique in any case

4 months ago

Thanks for letting me know! I was unaware of this 😱

I just refactored all my pre-control stage code to not use globals. I'll include it with the next update!

New response