[kovarex] [0.16.43] on_trigger_created_entity (ID 22) problem

Bugs that are actually features.
Post Reply
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

[kovarex] [0.16.43] on_trigger_created_entity (ID 22) problem

Post by TheSAguy »

Hi,
I'm posting this as a bug, since this was suggested to be a possible game bug fromthis thread

I updated my mod to have biters attack when cliffs get bombed. In testing I found no errors and all seemed to work fine, but I've gotten a few crash reports.


They are:
Image

and
Error
I've attached the mod. I've also attached a save from the first error report, but I can't load it, get this error:
Error_when_loading_save
It seems that for some reason, the cliffs are being triggered, but are not valid....

Here is the code that is erroring out: (it's the "if settings" line

Code: Select all

script.on_event(defines.events.on_trigger_created_entity, function(event)
	
	local entity = event.entity	

    if settings.startup["NE_Tree_Hugger"].value and global.cliff_explosive[entity.name] then
		writeDebug("Cliff Bombed")
		Look_and_Attack(entity, 2)
    end	

end)
I've defined my global in both init and config change:

Code: Select all

---------------------------------------------				 
local function On_Init()

	global.cliff_explosive = {} 
	global.cliff_explosive["ground-explosion"] = "ground-explosion"

end

---------------------------------------------				 
local function On_Config_Change()

	global.cliff_explosive = {} 
	global.cliff_explosive["ground-explosion"] = "ground-explosion"

end
---------------------------------------------

script.on_configuration_changed(On_Config_Change)
script.on_init(On_Init)
I gave "cliff-explosives" a trigger flag with the below code in my "data-updates.lua"

Code: Select all

if NE_Enemies.Settings.NE_Tree_Hugger == true then

	local proj = data.raw["projectile"]["cliff-explosives"]
	if proj and proj.action then
		local action = proj.action[1].action_delivery.target_effects
		for _, eff in pairs(action) do
			if eff.type == "create-entity" and eff.entity_name == "ground-explosion" then
				eff.trigger_created_entity = true
				break
			end
		end
	end
	
end
Again, everything seems to work when I test it in new games.
Thanks for taking a look.
Attachments
Natural_Evolution_Enemies_8.1.3.zip
Mod
(210.53 KiB) Downloaded 21 times
_autosave3.zip
Save
(6.95 MiB) Downloaded 33 times

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [kovarex] [0.16.43] on_trigger_created_entity (ID 22) problem

Post by kovarex »

First of all, the loading error is just a plain script error (it should be surfaces, not surface).
After fixing it in the control.lua. I cheated some cliff explosives and bombed some cliffs and got no errors.


Second of all, it doesn't take much time to see what is wrong in this code. You call entity.die() in the first block, and then you use the entity.name in the second block.

Code: Select all

script.on_event(defines.events.on_trigger_created_entity, function(event)
	
	local entity = event.entity	
	
	--- Unit Cluster created by Worm Launcher Projectile 
    if global.launch_units[entity.name] then
		writeDebug("Cluster Unit Created")
		entity.die()
    end

	--- Unit Cluster created by Worm Launcher Projectile 
    if settings.startup["NE_Tree_Hugger"].value and global.cliff_explosive[entity.name] then
		writeDebug("Cliff Bombed")
		Look_and_Attack(entity, 2)
    end	

end)

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: [kovarex] [0.16.43] on_trigger_created_entity (ID 22) problem

Post by TheSAguy »

Thanks Kovarex, that was a rookie mistake on my end!

Post Reply

Return to “Not a bug”