Is it possible to make ores grow?

Place to post guides, observations, things related to modding that are not mods themselves.
Zillo7
Inserter
Inserter
Posts: 22
Joined: Sun May 14, 2017 10:45 pm
Contact:

Re: Is it possible to make ores grow?

Post 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
Kynaro
Burner Inserter
Burner Inserter
Posts: 12
Joined: Thu May 18, 2017 2:48 pm
Contact:

Re: Is it possible to make ores grow?

Post 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?
Zillo7
Inserter
Inserter
Posts: 22
Joined: Sun May 14, 2017 10:45 pm
Contact:

Re: Is it possible to make ores grow?

Post 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?
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Is it possible to make ores grow?

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
orzelek
Smart Inserter
Smart Inserter
Posts: 3924
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Is it possible to make ores grow?

Post by orzelek »

Take a look here at various find commands for surface:
http://lua-api.factorio.com/latest/LuaSurface.html
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Is it possible to make ores grow?

Post by bobingabout »

Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
Zillo7
Inserter
Inserter
Posts: 22
Joined: Sun May 14, 2017 10:45 pm
Contact:

Re: Is it possible to make ores grow?

Post 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'?
Zillo7
Inserter
Inserter
Posts: 22
Joined: Sun May 14, 2017 10:45 pm
Contact:

Re: Is it possible to make ores grow?

Post by Zillo7 »

It's working now! Here's a webm of uranium spreading.
https://webmshare.com/rN5v4
Zillo7
Inserter
Inserter
Posts: 22
Joined: Sun May 14, 2017 10:45 pm
Contact:

Re: Is it possible to make ores grow?

Post 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?
Post Reply

Return to “Modding discussion”