Problems with LuaEntity.orientation

Place to get help with not working mods / modding interface.
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1111
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Problems with LuaEntity.orientation

Post by Pi-C »

LuaEntities have two properties that affect their direction: direction and orientation. The first is rather rough, the other more fine-grained. Only direction can be used with LuaSurface.create_entity.

Yesterday, I noticed something peculiar:

Code: Select all

    name = player.character.name
    position = player.character.position
    surface = player.surface
    force = player.force
    direction = player.character.direction
    orientation = player.character.orientation

    log("direction: " .. direction .. "\torientation: " .. orientation)

    player.character = surface.create_entity{name = name, position = position, direction = direction, force = force, fast_replace = true, raise_built = true}
    
    log("direction: " .. player.character.direction .. "\torientation: " .. player.character.orientation)
Before the character was replaced, I've logged these values:
direction: 3
orientation: 0.375

So the character was facing towards Southeast. After the new character had been created, I've got these values:
player.character.direction: 2
player.character.orientation: 0.25

So the character was facing eastwards. Now, I thought I'd adjust orientation to let the new character face SE again:

Code: Select all

    if player.character then
      player.character.orientation = orientation

      log("After changing orientation. direction: " .. player.character.direction .. "\torientation: " .. player.character.orientation)

    end
Surprise, surprise! The new character was still facing eastwards. However, this change did the trick:

Code: Select all

    if player.character then
      player.character.direction = direction

      log("After changing direction direction: " .. player.character.direction .. "\torientation: " .. player.character.orientation)

    end
The new character was finally looking into the same direction as the old one. However, the log still shows these values after applying the change to player.character.direction still :
player.character.direction: 2
player.character.orientation: 0.25

What's going on here?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Modding help”