[MOD 0.12.x] Autowire - configurable automated pole wiring

Topics and discussion about specific mods
Peter34
Smart Inserter
Smart Inserter
Posts: 1100
Joined: Mon Nov 10, 2014 12:44 pm
Contact:

Re: [MOD 0.12.x] Autowire - configurable automated pole wiring

Post by Peter34 »

EDIT: Nevermind, the 1.4 auto-wire actually works. Or at least doesn't give an error. I'm able to start the game with it. Sorry for the inconvenience.



Happens right upon starting a new game, after I select the map options then click "Generate"

Notice

__autowire__/control.lua:102:attempt to index global 'game' (a nil value)

OK

When I click OK, the window closes, and if I click "Generate" I get that window again. So the mod basically can't be used, at least for starting a new game.

SirRichie
Fast Inserter
Fast Inserter
Posts: 244
Joined: Wed Feb 25, 2015 4:50 pm
Contact:

Re: [MOD 0.12.x] Autowire - configurable automated pole wiring

Post by SirRichie »

This error was due to the changes in the modding API, which required many mods to be adjusted

GopherAtl
Fast Inserter
Fast Inserter
Posts: 177
Joined: Sat Jan 31, 2015 7:54 pm
Contact:

Re: [MOD 0.12.x] Autowire - configurable automated pole wiring

Post by GopherAtl »

Thanks @Narc for updating this in my absence; should it become obsolete again, you, or anyone, is welcome and encouraged to steal and re-post a fixed version of the mod; that's the whole reason I share the source on github. This mod, in particular, is, at least for me, such a valuable Quality of Life thing when playing with circuit networks that I'd hate to see my inability to stay addicted to one thing for long cause the mod to disappear for anyone else who feels the same way.
My Mods:
Nixie Tubes - numeric displays for your circuit networks!
Logistic Combinators - use logistics values in circuit logic! -
Autowire - automate red/green wire connections

golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: [MOD 0.12.x] Autowire - configurable automated pole wiring

Post by golfmiketango »

I wrote: Hey, I tried this in 0.12.32 and although things mostly worked, my save eventually got corrupted somehow. The error message was something to the effect of "gui element named autowire_flow already exists." Don't really have enough confidence in my understanding of lua and/or factorio modding to send this as a PR yet but here's how I worked around it:

Code: Select all

diff --git a/control.lua b/control.lua
index 843048b..307cd97 100644
--- a/control.lua
+++ b/control.lua
@@ -36,8 +36,10 @@ end
 
 function createMainGUI(player)
   local settings=getPlayerSettings(player)
-  player.gui.top.add{type="flow",name="autowire_flow",direction="vertical"}
-  player.gui.top.autowire_flow.add{type="button", caption="Auto-wires",name="autowire",style="autowire_small_button_style"}
+  if not player.gui.top.autowire_flow then
+    player.gui.top.add{type="flow",name="autowire_flow",direction="vertical"}
+    player.gui.top.autowire_flow.add{type="button", caption="Auto-wires",name="autowire",style="autowire_small_button_style"}
+  end
   if settings.visible then
     showSettings(player)
   end
W4M, I use it all the time, now, without problems. I've gone ahead and made a PR equivalent to the above (I never bothered to git-format-patch and carelessly bit-bucketed my repo, so it's not the same commit exactly).

golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: [MOD 0.12.x] Autowire - configurable automated pole wiring

Post by golfmiketango »

I wrote:
I wrote: Hey, I tried this in 0.12.32 and although things mostly worked, my save eventually got corrupted somehow. The error message was something to the effect of "gui element named autowire_flow already exists." Don't really have enough confidence in my understanding of lua and/or factorio modding to send this as a PR yet but here's how I worked around it:

Code: Select all

diff --git a/control.lua b/control.lua
index 843048b..307cd97 100644
--- a/control.lua
+++ b/control.lua
@@ -36,8 +36,10 @@ end
 
 function createMainGUI(player)
   local settings=getPlayerSettings(player)
-  player.gui.top.add{type="flow",name="autowire_flow",direction="vertical"}
-  player.gui.top.autowire_flow.add{type="button", caption="Auto-wires",name="autowire",style="autowire_small_button_style"}
+  if not player.gui.top.autowire_flow then
+    player.gui.top.add{type="flow",name="autowire_flow",direction="vertical"}
+    player.gui.top.autowire_flow.add{type="button", caption="Auto-wires",name="autowire",style="autowire_small_button_style"}
+  end
   if settings.visible then
     showSettings(player)
   end
W4M, I use it all the time, now, without problems. I've gone ahead and made a PR equivalent to the above (I never bothered to git-format-patch and carelessly bit-bucketed my repo, so it's not the same commit exactly).
But, I think I found a bug either in your code or introduced by my patch. If I leave the GUI open when I save, and then later load my save, the settings (at least for copper wire, but I presume for all of them) are not respected in the game (despite being preserved and correctly reflected in the gui). Instead it behaves as if the defaults (copper:y, r:n, b:n) are in effect. Toggling and un-toggling the settings works around this but clearly there is a fixable problem in that the global state is being deserialized correctly, but not respected in the business logic... If I can figure out a way to fix it, I'll do so and push to github so it flows into my pr.

GopherAtl
Fast Inserter
Fast Inserter
Posts: 177
Joined: Sat Jan 31, 2015 7:54 pm
Contact:

Re: [MOD 0.12.x] Autowire - configurable automated pole wiring

Post by GopherAtl »

Not sure if you've fixed the last minor issue or not, but save corruption being a much bigger problem, I've merged and updated based on your PR now. Much appreciated, editing the updated download 0.1.15 version into the OP now.
My Mods:
Nixie Tubes - numeric displays for your circuit networks!
Logistic Combinators - use logistics values in circuit logic! -
Autowire - automate red/green wire connections

golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: [MOD 0.12.x] Autowire - configurable automated pole wiring

Post by golfmiketango »

As you know by now, I never did get around to trying to fix it. I suspect it's something to do with createMainGUI() operating on "settings" but then immediately throwing that away with "settings=global.autowire.settings" in load(), although how to fix it is not obvious to me due to being a factorio modding ignoramus.

golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: [MOD 0.12.x] Autowire - configurable automated pole wiring

Post by golfmiketango »

Crap. New campaign and got it again:
kablooey.jpg

Code: Select all

  function showSettings(player)
    local settings=getPlayerSettings(player)
30>>player.gui.top.autowire_flow.add{type="frame",caption="",name="settings",direction="vertical", style="autowire_frame_style"}
    player.gui.top.autowire_flow.settings.add{type="checkbox",caption="Copper",name="aw_s_copper",state=settings.copper,direction="vertical",style="checkbox_5"}
So it seems there remain ways to cause this crash. This made me sad.

At least this time I don't insta-crash on loading my save, which is a small improvement. However without disabling autowire I presume there'd be no way to ever close the autowire gui for the rest of my campaign (I guess something about simply being "unable" to load one's save at all can induce a bit of panic*).

--

* For me and probably most anyone who will have read this far, there would be an easy and obvious work around: disable autowire. A huge percentage of nontechnical people, however, would have been incapable of determining their inability to load their game was caused by autowire, because they instantly and without hesitation click through dialogs like this without reading them. To these people, a message like that appears to be in "computer-jibber-jabber," a language they have incorrectly convinced themselves they are utterly incapable of understanding. That's why, when they make a bug report like "factorio gives an error," they so genuinely seem to believe they have given all the relevant information. To a developer this can seem like laziness or someone who just wanted to complain; but usually, I think the real reason is the bug reporter is one of these error-message myopes -- that is, they do not have a motivational problem, but a learned aversion to reading purportedly "helpful" messages that so often seem like incomprehensible euphemisms for "prepare to get fucked in your virtual ass." Indeed, I must admit, that's precisely the practical significance of the message above to an end-user :).
Last edited by golfmiketango on Fri Jun 03, 2016 9:12 am, edited 1 time in total.

golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: [MOD 0.12.x] Autowire - configurable automated pole wiring

Post by golfmiketango »

golfmiketango wrote:
kablooey.jpg

Code: Select all

  function showSettings(player)
    local settings=getPlayerSettings(player)
30>>player.gui.top.autowire_flow.add{type="frame",caption="",name="settings",direction="vertical", style="autowire_frame_style"}
    player.gui.top.autowire_flow.settings.add{type="checkbox",caption="Copper",name="aw_s_copper",state=settings.copper,direction="vertical",style="checkbox_5"}
aha. Not the same crash, actually, just the same type of crash. The previous one was for autowire_flow, this one is for autowire_flow.settings. The same naive solution prevents the crash but also introduces at least one new bug:

Code: Select all

diff --git a/control.lua b/control.lua
index 307cd97..00a5819 100644
--- a/control.lua
+++ b/control.lua
@@ -27,10 +27,12 @@ end
 
 function showSettings(player)
   local settings=getPlayerSettings(player)
-  player.gui.top.autowire_flow.add{type="frame",caption="",name="settings",direction="vertical", style="autowire_frame_style"}
-  player.gui.top.autowire_flow.settings.add{type="checkbox",caption="Copper",name="aw_s_copper",state=settings.copper,direction="vertical",style="checkbox_5"}
-  player.gui.top.autowire_flow.settings.add{type="checkbox",caption="Red",name="aw_s_red",state=settings.red,direction="vertical",style="checkbox_10"}
-  player.gui.top.autowire_flow.settings.add{type="checkbox",caption="Green",name="aw_s_green",state=settings.green,direction="vertical",style="checkbox_15"}
+  if not player.gui.top.autowire_flow.settings then
+    player.gui.top.autowire_flow.add{type="frame",caption="",name="settings",direction="vertical", style="autowire_frame_style"}
+    player.gui.top.autowire_flow.settings.add{type="checkbox",caption="Copper",name="aw_s_copper",state=settings.copper,direction="vertical",style="checkbox_5"}
+    player.gui.top.autowire_flow.settings.add{type="checkbox",caption="Red",name="aw_s_red",state=settings.red,direction="vertical",style="checkbox_10"}
+    player.gui.top.autowire_flow.settings.add{type="checkbox",caption="Green",name="aw_s_green",state=settings.green,direction="vertical",style="checkbox_15"}
+  end
   settings.visible=true
 end

But if I do that, and I load my game, I click "Autowire", and nothing happens the first time (after that everything works right). Probably the same object life-cycle problem as the previous one behind it.

Post Reply

Return to “Mods”