GDIW - Gah! DarnItWater!


Allows switching liquid recipe inputs and outputs.

Utilities
3 years ago
0.13 - 1.1
44.0K

g getting an error with the new version

7 years ago
(updated 7 years ago)

gdiw/data-final-fixes.lua:89:attempt to get length of field 'results' (a nil value)

7 years ago
(updated 7 years ago)
7 years ago
(updated 7 years ago)

I had a similar problem in the same place. I thought it was the same error at first, and I changed the condition on line 89 to "vrn.results and #vrn.results == 1" to prevent it, but then I noticed that it wasn't the same error at all. It was actually in the next line, saying "attempt to index field '?' (a nil value)".

By separating the nested accesses on line 90 into named variable assignments, I was able to tell that it was the attempt to access ".name" on "vrn.results[0]" that caused it. Apparently, even if vrn.results exists and has a length of 1, vrn.results[0] can still be nil. I know next to nothing about Lua, but I presume that the lone table element may be stored under any index, not just '0'.

For now I just commented out line 89 and 90 and let the code default to the "placeholder" icon.

7 years ago

Okay, after a bit of experimentation, I did this:

<pre>elseif vrn.results and #vrn.results == 1 then local SW_result = table.remove(vrn.results) table.insert(vrn.results, SW_result) table.insert(newicons,{icon=data.raw.item[SW_result.name].icon}) </pre>

I'm sure that's a horrible kludge, but I don't know enough Lua to make anything elegant. By accessing the table like a stack and popping the last element into a local variable, I can access it without having to rely on it being at index 0. Then I push it back onto the stack, to prevent its absence from causing problems downstream - which might actually put it at index 0 this time.

There must be a nicer way to do this, I'm sure, but this is the first time I ever did anything with Lua.

7 years ago

As I was playing, I noticed that the reversed Sulfur recipe got a broken icon as a result (and others as well, IIRC). So I tried a different horrible kludge to try and fix it.

<pre>elseif vrn.results and #vrn.results == 1 then for _,SW_result in pairs(vrn.results) do table.insert(newicons,{icon=data.raw.item[SW_result.name].icon}) end </pre>

Doing a single-loop iteration over a single-element table is also definitely not the correct way to get at said element, but this variant doesn't alter the table index of the element, which seems to fix the broken icons. I'll check the Lua documentation some time later and learn about the right way to find that element directly.

7 years ago

okay, I see that code, but where do I insert it?

New response