Page 1 of 1
game.createentity doesn't work as expected
Posted: Sat May 23, 2015 3:54 pm
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?
Re: game.createentity doesn't work as expected
Posted: Sun May 24, 2015 8:08 pm
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?
Re: game.createentity doesn't work as expected
Posted: Tue May 26, 2015 6:32 am
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.
Re: game.createentity doesn't work as expected
Posted: Tue May 26, 2015 8:25 pm
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.