debuging ability

Place to get help with not working mods / modding interface.
Post Reply
Iccor56
Long Handed Inserter
Long Handed Inserter
Posts: 65
Joined: Mon Dec 25, 2017 12:29 am
Contact:

debuging ability

Post by Iccor56 »

so i have this proof of concept code

Code: Select all

---------------- Event Listeners --------------
local function Blueprint_Scanner_on_scanner_on_tick(event)
   --if(event.tick%300==0) then
   if(event.tick==3977400) then

				log(event.tick)
		end
end

local function Blueprint_Scanner_on_built_entity(event)
  log("on_built_entity start")
	log(event.name )
	log(event.tick )
	log(event.stack.name )
end

local function Blueprint_Scanner_on_player_mined_entity(event)
  log("on_player_mined_entity start")
	log(event.name )
	log(event.tick )
	log(event.entity .name )
end


script.on_event(defines.events.on_tick, Blueprint_Scanner_on_scanner_on_tick)
script.on_event(defines.events.on_built_entity, Blueprint_Scanner_on_built_entity)
script.on_event(defines.events.on_player_mined_entity, Blueprint_Scanner_on_player_mined_entity)

and i am wondering is there a better way to see what is going on in the code while it runs?
is there a way to see what events fire when something happens?

5535.467 Checksum for script __auto-research__/control.lua: 1845512852
5535.469 Checksum for script __BlueprintScanner__/control.lua: 1367157860
5535.510 Checksum for script __creative-mode-fix__/control.lua: 1436553039
5599.441 Script @__BlueprintScanner__/control.lua:18: on_player_mined_entity start
5599.441 Script @__BlueprintScanner__/control.lua:19: 65
5599.441 Script @__BlueprintScanner__/control.lua:20: 3983759
5599.442 Script @__BlueprintScanner__/control.lua:21: blueprint-scanner
5601.034 Script @__BlueprintScanner__/control.lua:11: on_built_entity start
5601.034 Script @__BlueprintScanner__/control.lua:12: 6
5601.034 Script @__BlueprintScanner__/control.lua:13: 3983855
5601.034 Script @__BlueprintScanner__/control.lua:14: blueprint-scanner
is there a way to output event names instead of numbers?

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

Re: debuging ability

Post by eradicator »

Iccor56 wrote:is there a way to output event names instead of numbers?
You'll have to build a reverse lookup table from defines.events.

Code: Select all

local lookup = {}
for name,number in pairs(defines.events) do 
  lookup[number] = name
  end
You can also subscribe to more than one event:

Code: Select all

script.on_event({event_name_1,event_name_2},function() --[[stuff!]] end)
Or to all events, by using the whole defines.events table directly.

Code: Select all

script.on_event(defines.events,function() --[[stuff!]] end)
This will result in lots of spam ofc, especially because it includes on_tick which you can remove using

Code: Select all

script.on_event(defines.events.on_tick,nil)
But it'll still be pretty spammy.

Also notice that defines.events does not know anything about custom events created by mods, so you can't lookup those. This will mainly be custom hotkeys (which have the name string as event.input_name though), but some larger mods do have "actual" events via script.generate_event_name().
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.

Post Reply

Return to “Modding help”