Page 1 of 1
lua function to get mod list
Posted: Wed Jul 03, 2013 10:18 pm
by midnight109
Ok, seems I have to manually create this data.raw table, but I can only find examples on doing it with known mods. I would like to create a data.raw for all mod items/entities/recipes that meet a type, in my current case, all mining-drill info on all loaded mods that are enabled/active. Since the mod-list.json carries all the info on the mods, i am looking for a means to have the control.lua of my mod, open that file, figure out what mods are thier that are enabled, get thier dir, and figure out what data files are loaded, ie, in my mod, it opens 4 luas in the data.lua, then run the files for the data:extend part and add all the data collected to the data.raw, then i can go threw it by type, in this case, a way to look at all the entities data that has a type "mining-drill" and make a copy of the needed data, then delete out the data.raw table, got the idea, just no idea how to do it in lua ._.
could someone walk me threw how to manage to do this <.< without my head exploding >.>
Re: lua function to get mod list
Posted: Wed Jul 03, 2013 10:38 pm
by FreeER
I think this should demonstrate it sufficiently for you xD
I added these lines to the ralmodpk's data.lua and used the collision/selection boxes to show a visual difference but if you wanted to change the speed you'd use the usual (effectivity, and mining_speed, instead of .collision_box and .selection_box)
Code: Select all
test = data.raw["mining-drill"]
test["fast-mining-drill"].collision_box = {{-5.4,-5.4},{5.4,5.4}}
for k,v in pairs(test) do
test[k].selection_box = {{-5.4,-5.4},{5.4,5.4}}
end
This makes the fast-mining-drill's collision box extremely large and the selection box for all mining-drill entities extremely large.
If you'd wanted to modify something on the creeper then you could use data.raw.unit["creeper"] because the name is creeper and it's entity type is unit.
Re: lua function to get mod list
Posted: Wed Jul 03, 2013 10:47 pm
by midnight109
no go
Code: Select all
test = data.raw["mining-drill"]
local t109 = test["fast-mining-drill"].resource_searching_radius
local t110 = test["basic-mining-drill"].resource_searching_radius
glob.player.print("test - " .. string.format("%d : 02%d", t109, t110))
no matter how I try to access data.raw its nil value, crashes with a error
Re: lua function to get mod list
Posted: Wed Jul 03, 2013 10:51 pm
by midnight109
the whole function -
Code: Select all
game.onevent(defines.events.onbuiltentity, function(event)
if event.createdentity.type == "mining-drill" then
glob.newMineWatcher = glob.newMineWatcher + 1
glob.MineWatcher[glob.newMineWatcher] = event.createdentity
for k,v in pairs(glob.MineWatcher) do
if not v.isvalid() then
table.remove(glob.MineWatcher, k)
glob.newMineWatcher=glob.newMineWatcher-1
else
local test = data.raw["mining-drill"]
local t109 = test["fast-mining-drill"].resource_searching_radius
local t110 = test["basic-mining-drill"].resource_searching_radius
glob.player.print("test - " .. string.format("%d : 02%d", t109, t110))
end
end
end
end)
i am trying to make a setup that will when you build something, it checks if its a drill, if so get its resource_search_radius from the entities vars so I can add a means of checking for depleted resources
Re: lua function to get mod list
Posted: Fri Jul 05, 2013 8:33 pm
by FreeER
Sorry for making a post that didn't actually end up helping, and then not replying back. I got interrupted by fourth of july celebrations with family.
The variables created in data.lua are only accessible from the data.lua (though you have probably figured that out by now)
hmmm, I was going to suggest using .getactive() but I just tested it and it returns true even if the drill isn't ontop of resources or connected to power so not very useful...
my second thought was getenergy. But that really only works if it has no power, not if it's out of resources since getenergy displays the same value whether the drill is working or not...I thought drills used 10% of their energy when not working...maybe getenergy doesn't reflect that idk (ah, looking at the wiki getenergy checks the machine's energy buffer, that explains it)
Well, I suppose I can't really help you out here
I think factorio will need to be updated with something to help you out which (unfortunately) I can not do lol