regenerate_entity syntax

Place to get help with not working mods / modding interface.
Post Reply
hreintke
Fast Inserter
Fast Inserter
Posts: 115
Joined: Mon Sep 04, 2017 6:52 pm
Contact:

regenerate_entity syntax

Post by hreintke »

Hi,

Maybe a lua misunderstanding from me but this what I face.

The function is defined as

Code: Select all

regenerate_entity(entities, chunks)
Regenerate autoplacement of some entities on this surface. This can be used to autoplace newly-added entities.

Parameters
entities :: string or array of string (optional): Prototype names of entity or entities to autoplace.
chunks :: array of ChunkPosition (optional): The chunk positions to regenerate the entities on. If not given all chunks are regenerated. Note chunks with status < entities are ignored.
Note: All specified entity prototypes must be autoplacable. If nothing is given all entities are generated on all chunks.
What I want to achieve is regenerate all entities in a specified number of chunks.
So : parameter entities -> not given
parameter chunks -> given

According to my lua knowledge & searching this should be done with f.e.

Code: Select all

game.player.surface.regenerate_entity(chunks = ...)
But when running :

Code: Select all

/c 
  local ca = {}
  ca[1] = {82,17}
  game.player.surface.regenerate_entity(chunks = ca)
I get : the error ") expected near ="

Running

Code: Select all

/c 
  local ca = {}
  ca[1] = {82,17}
  game.player.surface.regenerate_entity("tree-02", ca)
works as expected.

What syntax should I use ?

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: regenerate_entity syntax

Post by eradicator »

What you're trying here:

Code: Select all

 game.player.surface.regenerate_entity(chunks = ca)
is calling regenerate_entity with a table as argument, which would look like this:

Code: Select all

 game.player.surface.regenerate_entity({chunks = ca})
---or
 game.player.surface.regenerate_entity{chunks = ca}
But as regenerate_entity seems to take two independant arguments instead of a table (like most other API functions) you'd have to call it like this:

Code: Select all

 game.player.surface.regenerate_entity(nil,ca)
I.e. supplying two arguments, but the first one is empty.

Edit:
Hm...tried it, but doesn't work. Weird. Empty table just doesn't regenerate anything :o.
Edit2:
I asked a dev and they said it's not currently possibly to specify chunks without entities.

hreintke
Fast Inserter
Fast Inserter
Posts: 115
Joined: Mon Sep 04, 2017 6:52 pm
Contact:

Re: regenerate_entity syntax

Post by hreintke »

Thanks for clarification.

I did try the ("",ca) and (nil,ca) variants before I posted. Should have mentioned that.

Bad luck that the regenerate function is not really flexible.
Would be nice to have some options like "all except .." or based on types "only trees" or "no resources"

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: regenerate_entity syntax

Post by eradicator »

Can't you just autogenerate a list of all possibly regeneratable entities using LuaGameScript.decorative_prototypes, LuaGameScript.autoplace_control_prototypes, etc?

(Btw, more specifically: The API doesn't allow not specifying positional arguments that are followed by specified arguments. I.e. Any function that has positional arguments must always have all arguments up to the position you want.)

hreintke
Fast Inserter
Fast Inserter
Posts: 115
Joined: Mon Sep 04, 2017 6:52 pm
Contact:

Re: regenerate_entity syntax

Post by hreintke »

Thanks again.

Didn't know about that possibilty and will use it for sure

Post Reply

Return to “Modding help”