[1.1.33] Rotated locomotive returns wrong direction

Bugs that are actually features.
User avatar
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 793
Joined: Sun May 07, 2017 10:16 am
Contact:

[1.1.33] Rotated locomotive returns wrong direction

Post by ickputzdirwech »

I am a bit hesitant to post this here since I fear I just did something wrong but I am 99% certain this is not my fault. Anyway I wrote a mod that stops a train if one of its rolling stock gets destroyed and creates a ghost to replace it.

Code: Select all

script.on_event(defines.events.on_entity_died, function(event)
    	local entity = event.entity
	local train = entity.train
	-- stops the train
   	train.speed = 0
	-- creates ghost entity
    	game.surfaces[entity.surface.name].create_entity{
        	name = "entity-ghost",
       		inner_name = entity.name,
       		position = entity.position,
		direction = entity.direction,
        	force = entity.force,
        	create_build_effect_smoke = false,
        	 }
end, {{filter = "rolling-stock"}})
The issue I am having is that the created locomotive ghosts are the wrong way around if the destroyed locomotives got rotated before they got built.

Reproduction steps
  • Paste the code above into control.lua
  • Start a game and build some rails
  • Take a locomotive item
  • Press R
  • Build the locomotive
  • Shoot the locomotive
  • Observe that the created ghost is the wrong way around
If you rotate the locomotive after you build it you get the same issue.
If you do it without pressing R the locomotive has the right direction.
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3715
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: [1.1.33] Rotated locomotive returns wrong direction

Post by DaveMcW »

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 3003
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.33] Rotated locomotive returns wrong direction

Post by boskid »

Thanks for the report however i am moving this to Not a bug because your code is broken.

Your assumption is that the LuaEntity::direction will return direction of a rolling stock, but rolling stocks do not use directions so it always returns North. Please use LuaEntity::orientation and do create_entity{orientation=...} instead.
User avatar
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 793
Joined: Sun May 07, 2017 10:16 am
Contact:

Re: [1.1.33] Rotated locomotive returns wrong direction

Post by ickputzdirwech »

Thanks for your answer. That fixed it! :D :oops: In my defense: it's not documented in https://lua-api.factorio.com/latest/Lua ... ate_entity. I'll post it in documentation improvements.
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write
Post Reply

Return to “Not a bug”