game.createentity doesn't work as expected

Place to get help with not working mods / modding interface.
wahming
Fast Inserter
Fast Inserter
Posts: 192
Joined: Sun May 17, 2015 8:30 pm
Contact:

game.createentity doesn't work as expected

Post by wahming »

Using the following code:

Code: Select all

game.createentity {name = "basic-transport-belt", position = ent.position, direction = ent.direction, force = ent.force}
gives me a basic transport belt as expected. However, the belts do not join with each other cleanly as expected. E.g. when turning corners, they don't automatically reshape. Is there any command I can call to trigger a recalculation of the belt shape and layout?
Rseding91
Factorio Staff
Factorio Staff
Posts: 15875
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: game.createentity doesn't work as expected

Post by Rseding91 »

Can you post some images of what's happening? Because it works perfectly for me when I test it.

Are you adjusting the position of the belt? It looks like you're creating belts directly on top of another entity?
If you want to get ahold of me I'm almost always on Discord.
itzJanuary
Burner Inserter
Burner Inserter
Posts: 7
Joined: Mon May 25, 2015 9:45 am
Contact:

Re: game.createentity doesn't work as expected

Post by itzJanuary »

The only thing i figured is to use

Code: Select all

local buildEntity = {name = "basic-transport-belt", position = ent.position}
local player = game.player

--Make sure the player has nothing on the cursor
local cursorStackBackup = player.cursorstack
player.cursorstack = nil

--Set the mouse position
local oldPosition = player.cursorposition

player.cursorposition = game.real2screenposition({buildEntity.position.x, buildEntity.position.y})
player.cursorstack = {name = buildEntity.name, count = 1}
player.buildfromcursor()

--Return to the old location of the mouse and set the cursorstack again
player.cursorposition = oldPosition
player.cursorstack = cursorStackBackup
This is certainly not the best solution by a long shot but due to the nature of that 'buildfromcursor()' function you will get EXCACTLY the same behaviour as when the player would have placed something via mouseclick.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15875
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: game.createentity doesn't work as expected

Post by Rseding91 »

Are you making a belt on top of another belt trying to fast-replace it?

If so, you need to destroy the old belt first and then build the new belt.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Modding help”