Page 1 of 1

Surface and creating entities

Posted: Sun Sep 13, 2015 5:17 pm
by ninjadindon
Hi fellow modders,

I just came back to factorio and witnessed the changes in 0.12, create_entity now belongs to LuaSurface instead of LuaGame
The thing is I usually created entities at map generation near the player spawn with the event on_init and game.createentity
But now surface requires another entity to create one, eg: game.player.surface.create_entity{}

But on the event on_init, the player is not yet created, resulting in an error.
Is there a more appropriate way to call surface and create_entity without the help of the player ?
or is there another event called after the player initial spawn ?

(or should I monitor the how many times players have spawned and only call this on number one ?)

Thanks for the answers.

Re: Surface and creating entities

Posted: Sun Sep 13, 2015 5:29 pm
by Klonan
You can call a surface by its name

Code: Select all

game.surfaces.nauvis.create_entity
game.surfaces["nauvis"].create_entity

Re: Surface and creating entities

Posted: Sun Sep 13, 2015 5:36 pm
by ninjadindon
Thanks a lot mate,
It is very unfortunate that the factorio Lua Wiki is down, I woudn't bother you with silly questions