Page 2 of 2

Re: Is it possible to make ores grow?

Posted: Mon May 22, 2017 9:27 pm
by Zillo7
Kynaro wrote:
Try lower-case p instead of upper-case P? "ore.position"
That worked; now the ore grows! But it doesn't expand over time. This is the only part left that doesn't work; It fails when trying to find the uranium ore so it never reaches the line where it creates a new ore piece.

Code: Select all

    --add new ores to empty adjacent squares
    orePositions = {{ ore.position.x + 1, ore.position.y }, { ore.position.x - 1, ore.position.y }, 
{ ore.position.x, ore.position.y + 1 }, { ore.position.x, ore.position.y - 1 }}

    for i=0,3,1
    do
       local adjacentEntity = global.world.find_entities_filtered{position = orePositions[i], name = "uranium-ore"}
       if not adjacentEntity then
       --add new ore here
       local newOre = global.world.create_entity{name = "uranium-ore", position = orePositions[i], amount = 5}
       table.insert(global.oreList, newOre)
       end
    end

Re: Is it possible to make ores grow?

Posted: Tue May 23, 2017 10:14 pm
by Kynaro
I think you're trying to set the new ore position before you've found the current ore position? Or adjacentEntity is limited to searching for other uranium-ore entities, when it should just be looking for an empty tile?

Something about the find_entities_filtered parameters is my guess. Try just the position, and see what that does?

Re: Is it possible to make ores grow?

Posted: Fri May 26, 2017 12:05 am
by Zillo7
I'm reading the position of an existing ore piece and then I get the adjacent positions(the orePositions). It has something to do with find_entities_filtered; How do I check for an ore piece at a specific point?

Re: Is it possible to make ores grow?

Posted: Fri May 26, 2017 8:02 am
by bobingabout
Without looking it up, I'm fairly sure there's a "find entity at" command, where you pass it co-ordinates.
It's hard to check while I'm at work.

Re: Is it possible to make ores grow?

Posted: Fri May 26, 2017 9:39 am
by orzelek
Take a look here at various find commands for surface:
http://lua-api.factorio.com/latest/LuaSurface.html

Re: Is it possible to make ores grow?

Posted: Fri May 26, 2017 1:07 pm
by bobingabout

Re: Is it possible to make ores grow?

Posted: Sun May 28, 2017 5:36 pm
by Zillo7
bobingabout wrote:http://lua-api.factorio.com/latest/LuaS ... ind_entity
this is the one I was thinking of.
This works when searching for existing uranium ore, but is there a way to return anything that's at that point? The entity string argument is required, so is there a a string that's like 'ANYTHING'?

Re: Is it possible to make ores grow?

Posted: Sun May 28, 2017 6:30 pm
by Zillo7
It's working now! Here's a webm of uranium spreading.
https://webmshare.com/rN5v4

Re: Is it possible to make ores grow?

Posted: Mon May 29, 2017 11:22 pm
by Zillo7
I've encountered another problem though; when I'm trying to spread the ore over new squares, I end up creating new ore entities on the same squares as existing ore entities. Here's what I've got:

Code: Select all

orePositions = {{ ore.position.x + 1, ore.position.y }, { ore.position.x - 1, ore.position.y }, 
{ ore.position.x, ore.position.y + 1 }, { ore.position.x, ore.position.y - 1 }}

    for i=1,4,1
    do
       local adjacentEntity = global.world.find_entity(global.oreType, orePositions[i])
       if adjacentEntity == nil <-- fails here
	   then
       --add new ore here
       local newOre = global.world.create_entity{name = global.oreType, position = orePositions[i], amount = global.spreadAmount}
       table.insert(global.oreList, newOre)
       end
    end
For some reason, adjacentEntity is always null, which makes this script create a new ore entity on the same square as an existing one. Why is it doing this? Is my null check wrong, or is it not able to find the pre-existing ore entity?