[Rseding91][0.16.16][Modding] create_entity on ghosts

This subforum contains all the issues which we already resolved.
Post Reply
User avatar
lovely_santa
Filter Inserter
Filter Inserter
Posts: 502
Joined: Sat Feb 18, 2017 9:41 pm
Contact:

[Rseding91][0.16.16][Modding] create_entity on ghosts

Post by lovely_santa »

Hi,

On my mod (RSeding91's old forcefield mod) I get the issue of not been able to create entities when can_place_entity says it could

Code of the issue:

Code: Select all

surface.can_place_entity({name = emitterTable["type"], position = pos, direction = direction}) then
  local newField = surface.create_entity({name = emitterTable["type"], position = pos, force = force, direction = direction})

  -- This new entity will have 0 health on creation + one load of recharge this tick
  newField.health = Settings.forcefieldTypes[emitterTable["type"]]["chargeRate"]
  -- more code
The problem is that I have an automatic wall builder, and I have some gates inbetween that are not part of the auto builder.
When the gate is there, the can_pace_entity will say false, and ignore that tile to build a wall.
Then I manualy shoot the wall (or the biters will kill it) it shows up as a ghost for bots to replace it...

On the next iteration to check the wall, the can_place_entity will say true on the ghost..
--> I would say this is correct as you can place items over a ghost entity...

Then the next step is to create the entity. As stated it should be able to place it since its only a ghost...
But it won't place it on that entity and throw an error on the next line as i try to index a nil value as it didn't place the entity...
--> I think this methode should remove the ghost and place the entity, or if this isn't wanted the can_place_entity should at least give false?
error_message.png
error_message.png (66.38 KiB) Viewed 2999 times
I've added a safe file to test this out.
The only mod used is this pre-released update of the forcefield mod (also included)

To do: add the mod, open the world, shoot one of the gates near the player
(south east on the marked spot if you would spawn at spawn point)
It will replace the gate with a ghost (withing 10 seconds) and when it wants to build the entity it will give the error.
PS: shoot the gate on the red wall, that one will respawn the quickest

greetings
lovely_santa
Attachments
ForceFields2_2.0.1.zip
mod
(249.98 KiB) Downloaded 98 times
Forcefield_test3.zip
save file
(9.77 MiB) Downloaded 93 times
You can find all my mods on the mod portal. Also helping on Arch666Angel's mods.
Image

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

Re: [Rseding91][0.16.16][Modding] create_entity on ghosts

Post by Rseding91 »

Try adding force=... to the can_place_entity call.
If you want to get ahold of me I'm almost always on Discord.

User avatar
lovely_santa
Filter Inserter
Filter Inserter
Posts: 502
Joined: Sat Feb 18, 2017 9:41 pm
Contact:

Re: [Rseding91][0.16.16][Modding] create_entity on ghosts

Post by lovely_santa »

My bad, forgot to mension that, Klonan told me too, it had the same result

Code: Select all

          if surface.can_place_entity({name = emitterTable["type"], position = pos, direction = direction, force = force}) then
            local newField = surface.create_entity({name = emitterTable["type"], position = pos, force = force, direction = direction})

            -- Quick fix
            if newField == nil then
              game.print("Still a ghost in the way")
              entities = surface.find_entities({{pos.x-.5,pos.y-.5},{pos.x+.5,pos.y+.5}})
              for _,entity in pairs (entities) do
                entity.destroy()
              end
              newField = surface.create_entity({name = emitterTable["type"], position = pos, force = force, direction = direction})
            end

            -- More code
It stills report that there is not an entity there... I put up a quick fix for now.. and it prints it out each time
You can find all my mods on the mod portal. Also helping on Arch666Angel's mods.
Image

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

Re: [Rseding91][0.16.16][Modding] create_entity on ghosts

Post by Rseding91 »

Thanks for the report and easy way to reproduce the problem. It's now fixed for the next version of 0.16.
If you want to get ahold of me I'm almost always on Discord.

User avatar
lovely_santa
Filter Inserter
Filter Inserter
Posts: 502
Joined: Sat Feb 18, 2017 9:41 pm
Contact:

Re: [Rseding91][0.16.16][Modding] create_entity on ghosts

Post by lovely_santa »

So.. What was the mistake? the can_place_entity or the create_entity? I guess i'll find out on release
You can find all my mods on the mod portal. Also helping on Arch666Angel's mods.
Image

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

Re: [Rseding91][0.16.16][Modding] create_entity on ghosts

Post by Rseding91 »

lovely_santa wrote:So.. What was the mistake? the can_place_entity or the create_entity? I guess i'll find out on release
create_entity.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Resolved Problems and Bugs”