can_place_entity help [fixed]
Posted: Wed Mar 16, 2016 12:06 pm
Hi, I am working on a new mod, and for the mod I need to place belt entities. I found game.get_surface(1).can_place_entity{...} to check if it would work on lua-api.factorio.com. But I can't get it to work.
But, when I place a basic transport belt, the game gives this error:
With this code I though that because of the 'bad argument #-1' part the problem must be in the third argument, (one from the last.) But that variable is not nil, its the same direction as the placed entity, and printing that direction with game.player.print does not crash, or return nil.
I tried changing the variable to 'defines.direction.north' just for testing, but the same error occurred.
What is it that I'm doing wrong?
Matjojo
Code: Select all
script.on_event(defines.events.on_built_entity, function(event)
if event.created_entity.type == "transport-belt" then
BB_var_name = event.created_entity.name
BB_var_X = event.created_entity.position.x
BB_var_Y = event.created_entity.position.Y
BB_var_dir = event.created_entity.direction
BB_var_force = event.created_entity.force
if game.get_surface(1).can_place_entity{name = BB_var_name, position = {x = (BB_var_X + 1), y = (BB_var_Y)}, direction = BB_var_dir, force = BB_var_force} then
game.get_surface(1).create_entity{name = BB_var_name, position = {x = (BB_var_X + 1), y = (BB_var_Y)}, direction = BB_var_dir, force = BB_var_force}
end
end
end)
Code: Select all
Error while running the event handler: __BeltBrush__/control.lua:11: bad argument #-1 to 'can_place_entity' (number expected, got nil)
Line 11 is the line with can_place_entity in it.
I tried changing the variable to 'defines.direction.north' just for testing, but the same error occurred.
What is it that I'm doing wrong?
Matjojo