Surface and creating entities

Place to get help with not working mods / modding interface.
Post Reply
ninjadindon
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Apr 30, 2015 10:55 am
Contact:

Surface and creating entities

Post 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.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5151
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Surface and creating entities

Post by Klonan »

You can call a surface by its name

Code: Select all

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

ninjadindon
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Apr 30, 2015 10:55 am
Contact:

Re: Surface and creating entities

Post 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

Post Reply

Return to “Modding help”