'create_entity' (table expected, got number) error

Place to get help with not working mods / modding interface.
Post Reply
User avatar
bloc97
Inserter
Inserter
Posts: 47
Joined: Sat Apr 16, 2016 4:57 am
Contact:

'create_entity' (table expected, got number) error

Post by bloc97 »

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}
When I try to run the code above in a mod, the error occurs. Clearely "stringname" is a string, as I explicitely told the code to convert "ToString". Somehow the game API thinks that it is a number??

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)
Image-Vehicles, Defense, Energy & More!
Image-Keep inventory on death!

Rseding91
Factorio Staff
Factorio Staff
Posts: 13247
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: 'create_entity' (table expected, got number) error

Post by Rseding91 »

bloc97 wrote:

Code: Select all

... position=oldentity.direction} ...
If you want to get ahold of me I'm almost always on Discord.

User avatar
bloc97
Inserter
Inserter
Posts: 47
Joined: Sat Apr 16, 2016 4:57 am
Contact:

Re: 'create_entity' (table expected, got number) error

Post by bloc97 »

EDIT: Sorry, I can't read properly, found the problem, it was a small typo in the variables. Thanks for the help.
Image-Vehicles, Defense, Energy & More!
Image-Keep inventory on death!

Post Reply

Return to “Modding help”