Relik77 / factorio_computer_core

MIT License
7 stars 4 forks source link

A couple of items... #1

Closed wgorman closed 6 years ago

wgorman commented 6 years ago

Great plugin! I've been playing around with the new computer, I've had some decent success working with it.

One issue I found was in lan.lua. If a circuit value is reporting a negative number, the current code ignores it. I modified the plugin to use this logic instead:

if value.signal and value.signal.name and value.count ~= 0 then

The other issue I came across is every time I loaded a game that was running a program, the game would crash. I would get the following cryptic error message:

__computer_core__/logic/computerCommands.lua:600: attempt to index upvalue 'fs' (a nil value)

I never discovered the root cause of the issue (I'm still learning lua & the factorio mod environment) but I did work around it via this change to control.lua:raise_event:

            for index, validate in pairs(data.apis or {}) do
                local status, result = pcall(validate)
                if not status or not result then

Thanks!

wgorman commented 6 years ago

One additional thought... I'm not very fond of the copy / paste functionality in the factorio text-box, as you probably already discovered factorio removes new lines. This makes it difficult to build more complex projects with the computer mod. One idea I had is allowing an external read only mount to the filesystem. I hacked in a single file into /external/test but I could imagine allowing other plugins to register new code snippets in that manner. Hacking around Lua I discovered the local text = [==[ ]==] functionality, that along with an import worked well for me!

Relik77 commented 6 years ago

Thank you, I look at these points quickly.

And indeed, this concern with the copy / paste annoys me from the beginning and despite the hours trying to circumvent it, I had not found a solution. I will apronfonde your idea;)

Relik77 commented 6 years ago

Hi,

After long hours of debugging, I found and corrected the problem when loading a game that was running a program. It was a serialization / deserialization issue that resulted in a severe correction (Lua "loses" the runtime environment) :/

Main consequences:

ex:

local a = 3
local b = 4
os.wait (function (a, b)
    term.write (a) -- print "3"
end, 1, a, b)

In order to simplify writing, apis have emerged: os.set(name, ... args) os.get(name) os.clear(name)

ex:

local a = 3
local b = 4
os.set ("env1", a, b)
os.wait (function ()
    local a, b = os.get ("env1")
    term.write (a) -- print "3"
end, 1)

NB: lan.lua updated too. I chose : if value.signal and value.signal.name and type(value.count) == "number" then I'm looking now for the 2nd point of improvement ;-)

wgorman commented 6 years ago

Great! I've merged your latest changes and will try them out. Here's a new issue I encountered... In _readCombinatorSignal, if network.signals is empty I get errors. I fixed this by modifying the network check to:

if network and network.signals ~= Nil then

Thanks!

Will

Relik77 commented 6 years ago

Well, I validate the correction, even if I do not know in which case "network" can exist without "network.signals"