Table trouble

Place to get help with not working mods / modding interface.
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1645
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Table trouble

Post by Pi-C »

I just noticed something weird. In my new migration script, this code will run for every turret in my list:

Code: Select all

for t, turret in pairs(global.WT_turrets) do
  global.WT_turrets[t].area = WT.get_turret_area(turret.entity)

  if turret.entity.name ~= WT.steam_turret_name then
    global.WT_turrets[t].fire_dummies = {}
    global.WT_turrets[t].fires = {}
    WT.find_fire(turret.entity)
  else
    global.WT_turrets[t].fire_dummies = nil
    global.WT_turrets[t].fires = nil
  end
end
However,

Code: Select all

for t, turret in pairs(global.WT_turrets) do
…
end
in on_init or on_tick will only be executed for the first turret in the table. The table is indexed by turret.unit_number, the first turret in the list has the index 54, the next is 56. So why does this work as expected in the migration script but not in the game?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Table trouble

Post by darkfrei »

Pi-C wrote:
Sun Sep 13, 2020 6:50 am
in on_init or on_tick will only be executed for the first turret in the table. The table is indexed by turret.unit_number, the first turret in the list has the index 54, the next is 56. So why does this work as expected in the migration script but not in the game?
Set some LuaRendering to the checked entities, just to check that they are really ignored.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1645
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Table trouble

Post by Pi-C »

darkfrei wrote:
Sun Sep 13, 2020 10:35 am
Pi-C wrote:
Sun Sep 13, 2020 6:50 am
in on_init or on_tick will only be executed for the first turret in the table. The table is indexed by turret.unit_number, the first turret in the list has the index 54, the next is 56. So why does this work as expected in the migration script but not in the game?
Set some LuaRendering to the checked entities, just to check that they are really ignored.
Not at home right now, I'll do that later. But I have debugging output on where the function is entered, and I see always the same turret.unit_number there. Also, turrets should be replaced when the fluid supply changes, and I've noticed that it didn't work for most turrets -- because they don't enter the function where they would be replaced.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Table trouble

Post by DaveMcW »

Is your debugging output to game.print()? That has flood control which prevents some stuff from appearing.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1645
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Table trouble

Post by Pi-C »

DaveMcW wrote:
Mon Sep 14, 2020 2:14 am
Is your debugging output to game.print()? That has flood control which prevents some stuff from appearing.
That was it! Almost -- I've used log() instead of game.print(), but it was the output. Apparently there was a bug in my wrapper function which didn't manifest in a crash and worked most of the time, but the function choked on tables in some situations. For some reason, it showed the expected result when called from the migration script, but not during the game. After debugging my debugging tool, I've now managed to get at the core of the bug I was after: An immediate UPS drop to almost 0, caused by a vicious circle of creating entities and destroying them on the next tick, caused by testing for a variable that had been renamed everywhere else. :mrgreen:
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Modding help”