Code: Select all
oldentity.name = "test_x1"
oldentity.direction = {0,0}
local oldname=string.sub(oldentity.name, 1, -2) -- Removes last character
local newname=oldname.."2" -- Adds "2" to the end of string
local stringname=ToString(newname) -- Tries to convert to string (error occurs with and without this line)
game.players[1].print(oldname) --Prints on console "test_x1"
game.players[1].print(newname) --Prints on console "test_x2"
game.players[1].print(stringname) --Prints on console "test_x2"
local newent = game.get_surface(1).create_entity{name=stringname, position=oldentity.direction}
Edit: I tested with print, and it prints on the console as "test_x2".
Code: Select all
Error while running the event handler: __TestMod__/control.lua:45: bad argument #-1 to 'create_entity' (table expected, got number)