[Solved] Need help with Layered entities

Place to get help with not working mods / modding interface.
User avatar
anarchyinc
Inserter
Inserter
Posts: 29
Joined: Tue Jul 05, 2016 9:31 pm

[Solved] Need help with Layered entities

Post by anarchyinc »

Hello all, I just spent the whole day working on an idea I had to combine an electrical pole, lamp, and a roboport zone extender into one entity. So far I've used the wiki and older mods "concrete lamp post" as references and updated the script the best I could to v14.

After several sloppy edits, I can now place my new electrical pole down then the lamp and roboport addons will spawn into place. If I pick up the pole, the addons are removed as intended. Only issue I have left is that my new logistic addon isn't connecting to my existing network. If I place it down directly it will connect to the network but not to the script spawned entities. The script spawned addons WILL connect to each other.

I've obviously done something incorrectly but as I've never played around with complicated on_event scripts, I haven't got a clue what I did wrong. And even less of a clue on where to start looking.

sloppy update of control.lua from factorio v12
control
backbone.lua
backbone
Last edited by anarchyinc on Sat Sep 17, 2016 6:00 am, edited 2 times in total.
"Friends don't let friends drink & drive", "Gamers don't let gamers install steam"
User avatar
anarchyinc
Inserter
Inserter
Posts: 29
Joined: Tue Jul 05, 2016 9:31 pm

Re: Need help with Layered entities

Post by anarchyinc »

Looks like I can't do spoiler tags correctly either, I should go to bed.
"Friends don't let friends drink & drive", "Gamers don't let gamers install steam"
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Need help with Layered entities

Post by aubergine18 »

You missed the name (after the "=") from your spoiler

Code: Select all

[spoiler=This is my code]
 ... your code preferably wrapped in code tags ...
[/spoiler]
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Need help with Layered entities

Post by Nexela »

Also this might be the problem

force= game.forces.neutral


your logistic is looking for a network belonging to the neutral force and not the "player"s force

What you probaly want instead will be force=event.created_entity.force (or force=e.force in your case)
Last edited by Nexela on Sat Sep 17, 2016 5:20 am, edited 1 time in total.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Need help with Layered entities

Post by Nexela »

Also not related

surface.find_entities_filtered{area = {{X -0.5, Y - 0.5 }, {X + 0.5 , Y +0.5 }}, name= "backbone-light"}

If your looking for something in the same spot you can just use position

surface.find_entites_filtered{position=e.position, name="backbone-light"}
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Need help with Layered entities

Post by aubergine18 »

First script - cleaned up and with tweak to force and search position as mentioned by Nexela:

Code: Select all

-- luacheck: globals script defines game

local addon = { 'backbone-light', 'backbone-logistics' }

-- create addons when factory built
local function BuiltEntity(event)
  local entity = event.created_entity

  if entity.name == "factory-backbone" then
    -- spawn addons
    for name = 1, #addon do
      entity.surface.create_entity {
        name     = addon[name],
        position = entity.position,
        force    = entity.force
      }
      .destructible = false
    end--for
  end--if entity.name

end--BuiltEntity


-- remove addons when factory destroyed
local function MinedEntity(event)
  local entity = event.entity

  if entity.name == "factory-backbone" then
    -- remove addons
    for name = 1, #addon do
      local found = entity.surface.find_entities_filtered {
        name = addon[name],
        position = entity.position
      }
      if found[1] then found[1].destroy() end
    end--for
  end--if entity.name

end--MinedEntity

script.on_event(defines.events.on_built_entity, BuiltEntity)
script.on_event(defines.events.on_robot_built_entity, BuiltEntity)
script.on_event(defines.events.on_preplayer_mined_item , MinedEntity)
script.on_event(defines.events.on_entity_died , MinedEntity)
script.on_event(defines.events.on_robot_pre_mined , MinedEntity)
Last edited by aubergine18 on Sat Sep 17, 2016 5:42 am, edited 2 times in total.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Need help with Layered entities

Post by Nexela »

aubergine18 wrote:First script - cleaned up and with tweak to force and search position as mentioned by Nexela:
These do almost the exact same thing
local pos = entity.position
local position = { pos.x, pos.y }

entity.position = {x = 0, y = 0}
local pos = {0, 0}

Both are valid positions for anywhere a position is required

Same is true for area (90% sure on this)
area={top_left = {x=0, y=0}, bottom_right = {x=0, y=0}}
area={top_left = {0, 0}, bottom_right = {0, y}}
area={{x=0, y=0}, {x=0, y=0}}
area={{0, 0}, {x=0, y=0}}
area={{0, 0}, {0, 0}}
Last edited by Nexela on Sat Sep 17, 2016 5:41 am, edited 1 time in total.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Need help with Layered entities

Post by aubergine18 »

Nexela wrote: These do almost the exact same thing
local pos = entity.position
local position = { pos.x, pos.y }

entity.position = {x = 0, y = 0}
local pos = {0, 0}

Both are valid positions for anywhere a position is required
Ah yes, forgot about that one. I've been doing lots of stuff with color objects recently and those don't offer the same syntactic sugar as position objects.

EDIT: Updated script to make cleaner
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Need help with Layered entities

Post by Nexela »

aubergine18 wrote:
Nexela wrote: Both are valid positions for anywhere a position is required
Ah yes, forgot about that one. I've been doing lots of stuff with color objects recently and those don't offer the same syntactic sugar as position objects.

I figured that's what it was. color concept should really allow for this :)
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Need help with Layered entities

Post by aubergine18 »

Nexela wrote:I figured that's what it was. color concept should really allow for this :)
In my Style mod, it does :) And also hex strings are supported without needing to do `color = color '#F00'`, you can just do `color = '#F00'` 8-)
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
anarchyinc
Inserter
Inserter
Posts: 29
Joined: Tue Jul 05, 2016 9:31 pm

Re: Need help with Layered entities

Post by anarchyinc »

Nexela wrote:Also this might be the problem

force= game.forces.neutral


your logistic is looking for a network belonging to the neutral force and not the "player"s force

What you probaly want instead will be force=event.created_entity.force (or force=e.force in your case)
Thank you! That was exactly it, I could have swore I read somewhere in the forums it had to be set to neutral but that was from a post a few years ago. That control lua is confusing as hell to me. Now that it works I'm afraid to clean my sloppy code.
Image
"Friends don't let friends drink & drive", "Gamers don't let gamers install steam"
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: [Solved] Need help with Layered entities

Post by aubergine18 »

The reason the Concrete Lamppost mod uses neutral force is so player can't select the addons (they can select the post, but not the lamp). Although I think there's other ways to do this now (player selectable property in prototype, or when creating entity, can't remember which).
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
anarchyinc
Inserter
Inserter
Posts: 29
Joined: Tue Jul 05, 2016 9:31 pm

Re: [Solved] Need help with Layered entities

Post by anarchyinc »

aubergine18 wrote:The reason the Concrete Lamppost mod uses neutral force is so player can't select the addons (they can select the post, but not the lamp). Although I think there's other ways to do this now (player selectable property in prototype, or when creating entity, can't remember which).
Hum, I could still select what ever got placed down last by the script so I just removed the selection_box from the addons and it was good enough to test. Also, the cleaned code you sent leaves the light addon behind when picked up by player and bots. My original sloppy code works exactly as expected with force=e.force. I feel I can move on to other little tweaks and call my sloppy code good enough.

But thank you all very much for the help/advice.
"Friends don't let friends drink & drive", "Gamers don't let gamers install steam"
User avatar
anarchyinc
Inserter
Inserter
Posts: 29
Joined: Tue Jul 05, 2016 9:31 pm

Re: [Solved] Need help with Layered entities

Post by anarchyinc »

Update: I went ahead and added back in the selection boxes so you could connect circuit connections to all 3 entities. I also added that new code that will show you the roboport status the devs recently added. I almost forgot about that one and wasn't going to add it at all. Oh, and I had to add the "not_bluepritable" flag to the attachments for it to work along side selection boxes.

Just wanted to let the forum know in case someone else later tries to do the same thing.
Working example
Working example
factory backbone.png (271.5 KiB) Viewed 6386 times
"Friends don't let friends drink & drive", "Gamers don't let gamers install steam"
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: [Solved] Need help with Layered entities

Post by aubergine18 »

That looks awesome! Are you posting it to the mod portal?
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
anarchyinc
Inserter
Inserter
Posts: 29
Joined: Tue Jul 05, 2016 9:31 pm

Re: [Solved] Need help with Layered entities

Post by anarchyinc »

aubergine18 wrote:That looks awesome! Are you posting it to the mod portal?
Those graphics don't belong to me so I've got a request in the texture subforum. I used bob's logistic zone extender with a vanilla lamp pasted on top as a place holder. The graphics I made while I wait look pretty bad. I think I'm using too hi-res, my new things stick out too much. I like my new roboport though.
current test
"Friends don't let friends drink & drive", "Gamers don't let gamers install steam"
User avatar
demongo
Inserter
Inserter
Posts: 25
Joined: Sat Apr 13, 2019 11:09 pm
Contact:

Re: [Solved] Need help with Layered entities

Post by demongo »

is it on the portal or is it private, i really wanna check it out(even if its not updated)
mrvn
Smart Inserter
Smart Inserter
Posts: 5860
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: [Solved] Need help with Layered entities

Post by mrvn »

And if the entities are not blueprintable do the wire connections survive blueprints?
Xorimuth
Filter Inserter
Filter Inserter
Posts: 695
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: [Solved] Need help with Layered entities

Post by Xorimuth »

demongo wrote: Mon Sep 27, 2021 3:32 pm is it on the portal or is it private, i really wanna check it out(even if its not updated)
Looks like it is here: https://mods.factorio.com/mod/factory_backbone

(FYI for anyone else reading: this thread is from 2016!)
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
mrvn
Smart Inserter
Smart Inserter
Posts: 5860
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: [Solved] Need help with Layered entities

Post by mrvn »

Yeah, kind of dated. Have you tried if the mod still works when you bump the version in the info.json to current?
Post Reply

Return to “Modding help”