trying to create new game surface

Place to get help with not working mods / modding interface.
kingarthur
Smart Inserter
Smart Inserter
Posts: 1463
Joined: Sun Jun 15, 2014 11:39 am
Contact:

trying to create new game surface

Post by kingarthur »

im attempting to create a new surface layer and apon starting a new game i get an error stating that it can not index game.

this is the code from the control.lua file inside the mods folder. as far as i can tell according to the api doc it should be game.create_surface to make a new surface but it doesnt seem to work. most of the code has been commented out as i kept getting errors trying to generate a surface when the rocket silo is built.

Code: Select all

--script.on_event(defines.events.on_built_entity, function(event)

--local entity = event.created_entity
--local surface = game.surfaces

--if entity.name == "rocket-silo" then
	--if game.surfaces["Space"] == nil then
		game.create_surface("Space")
		--surface.daytime = 0.5
	--end
--end
--)
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5412
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: trying to create new game surface

Post by Klonan »

kingarthur wrote:im attempting to create a new surface layer and apon starting a new game i get an error stating that it can not index game.

this is the code from the control.lua file inside the mods folder. as far as i can tell according to the api doc it should be game.create_surface to make a new surface but it doesnt seem to work. most of the code has been commented out as i kept getting errors trying to generate a surface when the rocket silo is built.

Code: Select all

--script.on_event(defines.events.on_built_entity, function(event)

--local entity = event.created_entity
--local surface = game.surfaces

--if entity.name == "rocket-silo" then
	--if game.surfaces["Space"] == nil then
		game.create_surface("Space")
		--surface.daytime = 0.5
	--end
--end
--)
I think you are overcomplicating it somehow, this might be clearer:

Code: Select all

script.on_init(function()
  global.surface = game.surfaces.space or game.create_surface("space")
  global.surface.daytime = 0.5
  global.surface.freeze_daytime = true
end)

script.on_event(defines.events.on_build_entity, function(event)
  local entity = event.created_entity
  if not entity.name == "rocket-silo" then return end
  print("Rocket silo built")
end
Post Reply

Return to “Modding help”