The code from V1.1 no longer works and I couldn't find anything about it. This is how I solved it in V1.1:
Code: Select all
event.rocket.get_inventory(defines.inventory.rocket).get_contents()
Code: Select all
event.rocket.get_inventory(defines.inventory.rocket).get_contents()
Code: Select all
event
Code: Select all
Error while running event PicksRocketStats::on_rocket_launched (ID 10)
__PicksRocketStats__/control.lua:631: attempt to get length of local 'pi_rss_rocket_inventory' (a nil value)
You have to get the inventory of the rocket.cargo_pod
Code: Select all
local myCargoPod = event.rocket.cargo_pod
local myInventory = myCargoPod.get_inventory()
Code: Select all
attempt to index local 'myCargoPod' (a nil value)
Well `get_inventory()` by itself wouldn't work, you'd have to do `event.rocket.cargo_pod.get_inventory(defines.inventory.cargo_unit)`.picklock wrote: ↑Mon Nov 04, 2024 6:41 pm Thanks for the answer. I have tried it. it does not work with the following code (event = on_rocket_launched).I get the following error message with the 2nd line of the code above:Code: Select all
local myCargoPod = event.rocket.cargo_pod local myInventory = myCargoPod.get_inventory()
How can I access the cargo_pod and cargo_pod inventory? I am at a loss.Code: Select all
attempt to index local 'myCargoPod' (a nil value)
Code: Select all
Error while running event PicksRocketStats::on_rocket_launched (ID 10)
__PicksRocketStats__/control.lua:631: attempt to index field 'cargo_pod' (a nil value)
Code: Select all
local pi_rss_rocket_inventory = event.rocket.cargo_pod.get_inventory(defines.inventory.cargo_unit)
Code: Select all
data.lua
data.raw["item"]["accumulator"].send_to_orbit_mode = "automated"
control.lua
function test_on_rocket_launched(event)
if event.rocket and event.rocket.valid then
if event.rocket.cargo_pod then
game.print("rocket had a cargo pod!")
game.print(serpent.block(event.rocket.cargo_pod))
game.print("item count: " .. tostring(event.rocket.cargo_pod.get_item_count()))
else
game.print("no cargo pod detected!")
end
end
end
script.on_event(defines.events.on_rocket_launched, test_on_rocket_launched)