"UnknownKey" output on entity.position

Place to get help with not working mods / modding interface.
BlackParagon
Burner Inserter
Burner Inserter
Posts: 5
Joined: Wed Feb 01, 2017 3:23 pm
Contact:

"UnknownKey" output on entity.position

Post by BlackParagon »

Ran into another problem here, couldn't find a post which had me covered.

For some stuff I want to do I need the position of an entity when it is destroyed (aka it "died").

The actual underlying code is irrelevant at this point, my problem is that I cannot access the coordinates of the entity correctly.

Code: Select all

script.on_event(defines.events.on_entity_died, function(event)
	game.print("something died!")
	if event.entity.force.name == "enemy" then
            game.print("it was a critter!")
	    game.print(event.entity.position)
	end
end
)
So I get my first message w/out any problem and the check for the force also works flawlessly (second message is displayed too).
But when the game should print the coordinates of the entity to me, I only get the y coordinate and some gibberish infront.

It looks like this:

"UnknownKey":-140.323764

I am 100% sure the number is the y coordinate, because it decreases accordingly if I pull the biters closer to 0,0 and kill them, but I have no clue where the x coordinate went. I've already looked through the API documentation, maybe I overlooked something?

Thanks in advance!
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: "UnknownKey" output on entity.position

Post by Nexela »

You can't print a table like that (it is looking for a locale entry in this case)

either print each member directly

game.print("x="..event.entity.position.x .. " y=" .. event.entity.position.y)

or expand the whole table

game.print(serpent.line(event.entity.position, {comment=false}))
BlackParagon
Burner Inserter
Burner Inserter
Posts: 5
Joined: Wed Feb 01, 2017 3:23 pm
Contact:

Re: "UnknownKey" output on entity.position

Post by BlackParagon »

Ah, I see. I had also tried accessing it with entity.position[1] and [2] respectively, as I was told it would be an array (containing 2 variables). That makes sense then, thank you again!
Post Reply

Return to “Modding help”