pretty new here but I've really been enjoying the modding aspect.
I have a problem. I'm trying to access script.on_init so I can save a global variable but I keep getting the error " attempt to index global 'script' (a nil value)"
Here is my code:
Code: Select all
--[[ include used code ]]
require "util"
require "defines"
script.on_init(function()
glob.combined = {}
end)
game.on_event(defines.events.on_player_created, function()
game.player.insert({name="small-electric-pole", count =100})
end)
game.on_event(defines.events.on_built_entity, function(event)
if event.created_entity.name == "small-electric-pole" then
local newpole = event.created_entity
local newlight = game.get_surface(1).create_entity{name="small-lamp", position = newpole.position, force=game.forces.player}
table.insert(glob.combined,{pole,light})
i = 0
for k,v in pairs(glob.combined) do
i = i + 1
end
glob.combined[i].pole = newpole
glob.combined[i].light = newlight
end
end)
game.on_event(defines.events.on_preplayer_mined_item, function(event)
if (event.entity.name == "small-lamp") then
for k,v in pairs(glob.build) do
if (event.entity.equals(v.drill)) then
v.pole.destroy()
end
end
end
end)