Page 1 of 1
Weird issue...(0.17.79)
Posted: Sat Jan 25, 2020 3:59 pm
by Mernom
I'm trying to make a mod that makes longer ranged ammo, to be used with KS combat (since with that, the ammo max range limits the weapon's range, preventing sniper rifles from being usable)
Somehow I managed to get my PC to freeze on load, when my mod's load reaches 9%.
here is the current file.
looking at the task manager while it happens, factorio climbs in memory usage, while 'system' climbs in disk usage.
The reason this is here and not in the bug forum is that I don't know if I should put it there, since it's not the latest version.
Re: Weird issue... Potentially memory leak? (0.17.79)
Posted: Sat Jan 25, 2020 4:30 pm
by eradicator
Code: Select all
for _, ammo in pairs(data.raw.ammo) do
if ammo.name:find("magazine") and not ammo.name:find("cannon") and not ammo.name:find("shell") then
make_sniper_ammo(ammo.name, {range = 35,speed = 2})
end
end
You're expanding the ammo table while you're looping through it, without excluding the new entries → infinietly creates "-sniper-sniper-sniper-sniper..." ammo. Easiest fix would be "and not name:find("-sniper")" i guess.
Re: Weird issue... (0.17.79)
Posted: Sat Jan 25, 2020 10:12 pm
by Mernom
Ahh! That's true.Thank you for the tip.
Re: Weird issue... (0.17.79)
Posted: Sun Jan 26, 2020 11:27 am
by Mernom
Funny thing is, if I went all in on the design, it wouldn't happened since I plan to move the sniper ammo to a different category, and add a different filter to only do the function of "bullet" type ammo.
Edit: How do I manage to do that exactly? Tried ammo.name.ammo_type.caregory:find , but it doesn't idenify ammo_type.
Re: Weird issue... (0.17.79)
Posted: Mon Jan 27, 2020 5:10 am
by Honktown
Mernom wrote: Sun Jan 26, 2020 11:27 am
Funny thing is, if I went all in on the design, it wouldn't happened since I plan to move the sniper ammo to a different category, and add a different filter to only do the function of "bullet" type ammo.
Edit: How do I manage to do that exactly? Tried ammo.name.ammo_type.caregory:find , but it doesn't idenify ammo_type.
name is a string? That should give you a "name is not a table" error I think, unless you meant something like data.raw.ammo["name"].ammo_type.category. If you're doing the for _, ammo in pairs(data.raw.ammo) then it'd be ammo.ammo_type.category .
It's not relevant during the data phase, but :find is probably not nearly as efficient as == "thing", so if you're using specific terms during the control phase, it'd be better to use == . Just a side comment. Obviously searching within strings you have to use find or match.
Re: Weird issue...(0.17.79)
Posted: Mon Jan 27, 2020 12:32 pm
by Mernom
I figured out the issue... It was two fold. One, I was looking inside of data.raw.ammo.name.name.
second, ammo prototypes are weirdly structured, with two layers of nameless tables which contain the other properties.