create_entity Key "movement" not found in property tree

Place to get help with not working mods / modding interface.
sparr
Smart Inserter
Smart Inserter
Posts: 1521
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

create_entity Key "movement" not found in property tree

Post by sparr »

I'm calling LuaSurface::create_entity with just a few parameters and getting a weird error about a missing property table key.

Here's the block of code:

Code: Select all

  -- clone entities
  local master_entities = surface.find_entities({master_pos, {master_pos.x+32, master_pos.y+32}})
  for _, entity in ipairs(master_entities) do
    if entity.position.x ~= master_pos.x+32 and entity.position.y ~= master_pos.y+32 then
      if entity.type ~= "character" and entity.type ~= "player" then
        local amount = entity.type == "resource" and entity.amount or nil
        surface.create_entity{
          name= entity.name,
          position= {
            x= (entity.position.x - master_pos.x) * slave_dx + slave_pos.x + (master_pos.x > slave_pos.x and 1 or 0),
            y= (entity.position.y - master_pos.y) * slave_dy + slave_pos.y + (master_pos.y > slave_pos.y and 1 or 0)
          },
          direction= entity.direction,
          force= entity.force,
          -- TODO: more thorough cloning
          -- type-specific parameters
          amount= amount,
        }
      end
    end
  end
And here's the error:

Code: Select all

Error while running event world-mirror::on_chunk_generated (ID 12)
Key "movement" not found in property tree at ROOT
stack traceback:
__world-mirror__/control.lua:97: in function mirror_chunk
__world-mirror__/control.lua:130: in function <__world-mirror__/control.lua:116>
Line 97 is the call to surface.create_entity
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: create_entity Key "movement" not found in property tree

Post by bobingabout »

Basically, what it's telling you is that you're not accounting for all possible entity types, you're trying to clone an entity that has a movement key, but aren't setting one.

In such situations, it's more common to use a table.deepcopy (I think that's the command) to clone one table onto another, then edit the values you want changed afterwards (Like position in this instance), Though I'm not sure how that would work in this specific case either.

Perhaps something like this? (untested code)

Code: Select all

        new_entity = surface.create_entity(entity)
          new_entity.position= {
            x= (entity.position.x - master_pos.x) * slave_dx + slave_pos.x + (master_pos.x > slave_pos.x and 1 or 0),
            y= (entity.position.y - master_pos.y) * slave_dy + slave_pos.y + (master_pos.y > slave_pos.y and 1 or 0)
          }
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
sparr
Smart Inserter
Smart Inserter
Posts: 1521
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: create_entity Key "movement" not found in property tree

Post by sparr »

Thanks. It seems I was trying to clone a particle entity, which has some required properties.

Sadly those properties don't seem to be readable at all through the api.

I'll add an exception and not try to clone particles. And I'll cover more of the types.
Post Reply

Return to “Modding help”