local lplayer = game.player
What I don't understand is WHY this works for a new game but not for a saved one. What's happening here with the "game"?
If anyone wants the context: I'm trying to make a "test mod" where I clean every inventory slot when a new world is generated. I'm doing it in the on_load method because the on_init method seems to not like the 'player' field of 'game' (so I've setup a global var to know if it is a new game)
Code below:
Code: Select all
script:on_init(function(event)
global.empty_inventories = true
end)
script:on_load(function(event)
if global.empty_inventories == nil then
global.empty_inventories = true
if global.empty_inventories == true then
local lplayer = game.player
for i,6,1 do
lplayer.get_inventory(i).clear()
end
end
end)