mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 15:14:52 +09:00
More lua experimenting
This commit is contained in:
1 parent
103f01b6a2
commit
18a40ca806
1 file changed
+28
-3
@@ -5,10 +5,33 @@
|
||||
|
||||
-- print JSON of entire inventory and request slots to file
|
||||
-- TODO: Get requester slot data as well
|
||||
|
||||
-- requester slot data is game.players.character.get_request_slot(slot)
|
||||
-- returns {name="copper-plate", count=47} or nil if nothing is set
|
||||
-- maybe game.players.character.item_requests? http://lua-api.factorio.com/latest/LuaEntity.html#LuaEntity.item_requests
|
||||
|
||||
/c
|
||||
local requests = {}
|
||||
for i = 1, game.player.force.character_logistic_slot_count do
|
||||
requests[i] = game.players["Danielv123"].character.get_request_slot(i)
|
||||
end
|
||||
|
||||
local o = "Requests: "
|
||||
for k,v in pairs(requests) do
|
||||
o = o..v["name"]..": "..v["count"]..", "
|
||||
end
|
||||
game.print(o)
|
||||
|
||||
/c
|
||||
local inventory = game.players["Danielv123"].get_inventory(defines.inventory.player_main).get_contents()
|
||||
local quickbar = game.players["Danielv123"].get_quickbar().get_contents()
|
||||
local requestSlots = {}
|
||||
--[[ Get contents of requester slots into a table ]]
|
||||
local requests = {}
|
||||
for i = 1, game.player.force.character_logistic_slot_count do
|
||||
requests[i] = game.players["Danielv123"].character.get_request_slot(i)
|
||||
end
|
||||
|
||||
--[[ generate JS table (not JSON) ]]
|
||||
local o = "{inventory:{"
|
||||
for k,v in pairs(inventory) do
|
||||
o = o.."['"..k.."']:"..v..","
|
||||
@@ -16,10 +39,12 @@ end
|
||||
for k,v in pairs(quickbar) do
|
||||
o = o.."['"..k.."']:"..v..","
|
||||
end
|
||||
|
||||
o = o.."},requestSlots:{"
|
||||
for k,v in pairs(requestSlots) do
|
||||
o = o.."['"..k.."']:"..v..","
|
||||
for k,v in pairs(requests) do
|
||||
o = o.."['"..v["name"].."']:"..v["count"]..", "
|
||||
end
|
||||
o = o.."}}"
|
||||
game.print(o)
|
||||
game.write_file("test.txt", o)
|
||||
|
||||
Reference in new issue
Block a user