Weird issue...(0.17.79)

Place to get help with not working mods / modding interface.
Post Reply
Mernom
Fast Inserter
Fast Inserter
Posts: 122
Joined: Sun Jul 15, 2018 10:05 pm
Contact:

Weird issue...(0.17.79)

Post 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.
Attachments
factorio-current.log
(2.24 KiB) Downloaded 54 times
KS-Combat-sniper-fix_0.0.1.zip
(1.77 KiB) Downloaded 54 times
Last edited by Mernom on Sun Jan 26, 2020 12:05 pm, edited 1 time in total.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Weird issue... Potentially memory leak? (0.17.79)

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Mernom
Fast Inserter
Fast Inserter
Posts: 122
Joined: Sun Jul 15, 2018 10:05 pm
Contact:

Re: Weird issue... (0.17.79)

Post by Mernom »

Ahh! That's true.Thank you for the tip.
Last edited by Mernom on Sun Jan 26, 2020 12:05 pm, edited 1 time in total.

Mernom
Fast Inserter
Fast Inserter
Posts: 122
Joined: Sun Jul 15, 2018 10:05 pm
Contact:

Re: Weird issue... (0.17.79)

Post 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.

Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Weird issue... (0.17.79)

Post 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.
I have mods! I guess!
Link

Mernom
Fast Inserter
Fast Inserter
Posts: 122
Joined: Sun Jul 15, 2018 10:05 pm
Contact:

Re: Weird issue...(0.17.79)

Post 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.

Post Reply

Return to “Modding help”