Page 1 of 1
Neighbours
Posted: Tue Dec 19, 2017 4:33 pm
by Mango
I'm having problems with entity.neighbours parameter.
In documentation it says this:
When called on a pipe-connectable entity, this is an array of entity arrays of all entities a given fluidbox is connected to.
As I understand it it looks like this:
E = entity
p = parameter
|E1|E2|E3|....
|p1|p1|p1|
|p2|p2|p2|
.
.
.
But when I try to count how many neighbours does that middle pipe have, it says its 1.
I count it like this:
Code: Select all
function tableLength(anyTable)
local count = 0
for _ in pairs(anyTable) do count = count + 1 end
return count
end
Edit: Or is there and array for every entity type?
Re: Neighbours
Posted: Tue Dec 19, 2017 5:25 pm
by Rseding91
For fluidboxes the result is an array of array of entities.
Because 1 entity can have multiple fluidboxes of which each can be connected to multiple entities.
Re: Neighbours
Posted: Tue Dec 19, 2017 5:43 pm
by Mango
Thanks for the reply, but I think I do not undestand.
An entity can have multiple fluidboxes, thats obvious,
but how can 1 fluidbox connect to more entities?
Re: Neighbours
Posted: Tue Dec 19, 2017 5:49 pm
by Rseding91
Mango wrote:Thanks for the reply, but I think I do not undestand.
An entity can have multiple fluidboxes, thats obvious,
but how can 1 fluidbox connect to more entities?
The storage tank is 1 fluidbox but has 4 different in/outs. The standard pipe is 1 fluidbox but has 4 different in/outs.
A "fluid box" is the thing that holds the actual fluid. The little connection symbol you see with alt-info enabled is the connections to that 1 fluidbox.
Re: Neighbours
Posted: Tue Dec 19, 2017 5:51 pm
by Mango
Oooh... I thought fluidbox is a pipe connection
Sorry and thanks.
Re: Neighbours
Posted: Wed Dec 27, 2017 11:34 am
by KroshkaRoo
Hello.
I have a question about this same subject.
There is a mod, Subterrain_modified. Its main feature is long underground conveyors and pipes. Moreover, during construction, the distance between the entrance and the exit is calculated, and the necessary number of conveyor belts or pipes, depending on the distance, is taken from the player's inventory. And when dismantling - returns.
With conveyors, everything is fine, but with pipes ...
In Factorio 0.15 this script worked
Code: Select all
--actions for subterrain pipes on built
function subterrainPipesOnBuilt(event)
if settings.global["underground-pipe-cost-multiplier"].value <= 0 then return nil end --no pipe cost
local entity = event.created_entity
local player = game.players[event.player_index]
entity.rotatable = false --Prevent rotation, as that can be used to game the system
local otherPipe = entity.neighbours[2] or nil
if not otherPipe then
return nil --no need to do anything if this is the first placed
end
local distance = getDistance(entity, otherPipe)
local calc = (math.floor(distance * settings.global["underground-pipe-cost-multiplier"].value))
otherPipe.force = "player"
if checkCount(player, calc, "pipe") then
entity.destroy()
player.print("You don't have enough pipes in your inventory to create this length.")
player.print("You need " .. checkCount(player, calc, "pipe") .. " more. ")
restoreDeniedItem(player, sp)
else
player.remove_item{name = "pipe", count = calc} --charge the player the pipes
end
end
And in 0.16 it does not work anymore.
How to make it work?
Thank you.
P. S. Sorry, it is Google Translate.
Re: Neighbours
Posted: Wed Dec 27, 2017 12:36 pm
by KroshkaRoo
I found the solution to the problem.
Just a table with coordinates placed in another table.
The solution looks like this:
Code: Select all
local otherPipe = entity.neighbours[1][1] or nil
Thanks to all!

Re: Neighbours
Posted: Wed Dec 27, 2017 4:20 pm
by orzelek
For the future when you are not sure whats in property I recommend this:
Code: Select all
log(serpent.block(interesting_thing))
It's really useful for debugging too - especially of raw data on data stage.
Re: Neighbours
Posted: Wed Dec 27, 2017 4:43 pm
by Bilka
orzelek wrote:For the future when you are not sure whats in property I recommend this:
Code: Select all
log(serpent.block(interesting_thing))
That returns {} when printing entity.neighbours[1] in this case...
Re: Neighbours
Posted: Wed Dec 27, 2017 7:14 pm
by KroshkaRoo
orzelek wrote:For the future when you are not sure whats in property I recommend this:
Code: Select all
log(serpent.block(interesting_thing))
It's really useful for debugging too - especially of raw data on data stage.
This is helpful, thanks!
Re: Neighbours
Posted: Wed Dec 27, 2017 7:20 pm
by darkfrei
KroshkaRoo wrote:orzelek wrote:For the future when you are not sure whats in property I recommend this:
Code: Select all
log(serpent.block(interesting_thing))
It's really useful for debugging too - especially of raw data on data stage.
This is helpful, thanks!
or without comment
Code: Select all
my_text = serpent.block(my_table, {comment = false})