Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A couple of items... #1

Closed
wgorman opened this issue Nov 30, 2017 · 5 comments
Closed

A couple of items... #1

wgorman opened this issue Nov 30, 2017 · 5 comments
Labels

Comments

@wgorman
Copy link

wgorman commented Nov 30, 2017

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
Copy link
Author

wgorman commented Nov 30, 2017

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
Copy link
Owner

Relik77 commented Nov 30, 2017

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 added a commit that referenced this issue Dec 2, 2017
@Relik77
Copy link
Owner

Relik77 commented Dec 2, 2017

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:

  • Apis like "os.wait" or "wlan.on" have been modified to take as last parameters a series of variables to be transmitted during the callback

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
Copy link
Author

wgorman commented Dec 5, 2017

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
Copy link
Owner

Relik77 commented Dec 5, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants