Jump to content
injurytoall

Factory Monitor [Lua]

Recommended Posts

I created this for my org and I thought I'd share as I found it useful to be able to see the status of your machines from a single screen

 

Element Requirements:

 

x1 Programming Board
x1 Screen (Only got it working with a medium screen)
Access to your base core (for linking purposes)
1-8 Industry units

 

Linking Order of Elements:
[1]Core
[2]Screen
[3-10] Industry Unit

 

Setup:
 
Copy the following code
{"slots":{"0":{"name":"core","type":{"events":[],"methods":[]}},"1":{"name":"screen","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"screen.setHTML([[\n    <svg width=\"100vw\" height=\"60vw\" viewBox=\"0 0 45 45\" xmlns=\"http://www.w3.org/2000/svg\" stroke=\"#fff\">\n    <g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\" stroke-width=\"2\">\n        <circle cx=\"22\" cy=\"22\" r=\"6\" stroke-opacity=\"0\">\n            <animate attributeName=\"r\"\n                 begin=\"1.5s\" dur=\"3s\"\n                 values=\"6;22\"\n                 calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n            <animate attributeName=\"stroke-opacity\"\n                 begin=\"1.5s\" dur=\"3s\"\n                 values=\"1;0\" calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n            <animate attributeName=\"stroke-width\"\n                 begin=\"1.5s\" dur=\"3s\"\n                 values=\"2;0\" calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n        </circle>\n        <circle cx=\"22\" cy=\"22\" r=\"6\" stroke-opacity=\"0\">\n            <animate attributeName=\"r\"\n                 begin=\"3s\" dur=\"3s\"\n                 values=\"6;22\"\n                 calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n            <animate attributeName=\"stroke-opacity\"\n                 begin=\"3s\" dur=\"3s\"\n                 values=\"1;0\" calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n            <animate attributeName=\"stroke-width\"\n                 begin=\"3s\" dur=\"3s\"\n                 values=\"2;0\" calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n        </circle>\n        <circle cx=\"22\" cy=\"22\" r=\"8\">\n            <animate attributeName=\"r\"\n                 begin=\"0s\" dur=\"1.5s\"\n                 values=\"6;1;2;3;4;5;6\"\n                 calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n        </circle>\n    </g>\n</svg>\n    ]])","filter":{"args":[],"signature":"start()","slotKey":"1"},"key":"0"},{"code":"screen.clear()","filter":{"args":[],"signature":"stop()","slotKey":"1"},"key":"1"},{"code":"unit.setTimer(\"loading\", 5)","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"2"},{"code":"unit.setTimer(\"refresh\", 1)\nunit.stopTimer(\"loading\")","filter":{"args":[{"value":"loading"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"3"},{"code":"function round(number, precision)\n    local fmtStr = string.format('%%0.%sf',precision)\n    number = string.format(fmtStr,number)\n    return number\nend\n\nslots = {}\nif slot3 then \n    table.insert(slots,{slot3.getId(),slot3.getStatus(),slot3.getUptime(),slot3.getEfficiency(),slot3.getCycleCountSinceStartup()})\nend\nif slot4 then\n    table.insert(slots,{slot4.getId(),slot4.getStatus(),slot4.getUptime(),slot4.getEfficiency(),slot4.getCycleCountSinceStartup()})\nend\nif slot5 then\n    table.insert(slots,{slot5.getId(),slot5.getStatus(),slot5.getUptime(),slot5.getEfficiency(),slot5.getCycleCountSinceStartup()})\nend\nif slot6 then\n    table.insert(slots,{slot6.getId(),slot6.getStatus(),slot6.getUptime(),slot6.getEfficiency(),slot6.getCycleCountSinceStartup()})\nend\nif slot7 then\n    table.insert(slots,{slot7.getId(),slot7.getStatus(),slot7.getUptime(),slot7.getEfficiency(),slot7.getCycleCountSinceStartup()})\nend\nif slot8 then\n    table.insert(slots,{slot8.getId(),slot8.getStatus(),slot8.getUptime(),slot8.getEfficiency(),slot8.getCycleCountSinceStartup()})\nend\nif slot9 then\n    table.insert(slots,{slot9.getId(),slot9.getStatus(),slot9.getUptime(),slot9.getEfficiency(),slot9.getCycleCountSinceStartup()})\nend\nif slot10 then\n    table.insert(slots,{slot10.getId(),slot10.getStatus(),slot10.getUptime(),slot10.getEfficiency(),slot10.getCycleCountSinceStartup()})\nend\nlocal beginHtml = [[\n    <style>table{width:100%;font-size:19px;color:#99CC00;border-collapse:collapse;}td{width:20vw;border-bottom: 1px solid;text-align:center}tr{height: 60px}</style>\n    <body style=\"width:100%\">\n    <table>\n        <tr style=\"font-weight:bold;align-text:center;background-color:indigo;\">\n            <td>Machine</td>\n            <td>Status</td>\n            <td>Uptime(sec)</td>\n            <td>Efficiency</td>\n            <td>Cycle Count</td>\n        </tr>\n]]\nlocal endHtml = [[\n\t\n    </table>\n\t<tr>v1.0 // created by: injurytoall</tr>\n    </body>\n]]\nlocal dispHtml = '<tr>'\nfor i = 0,8 do\n    if slots[i] == nil then\n    else\n        local id = slots[i][1]\n        local col1 = database.getElement(core, id).name\n         \t\n        --status\n        local col2 = slots[i][2]\n        --uptime\n        local col3 = ''\n        local col4 = ''\n        local col5 = ''\n\n        local status = ''\n        --if machine is stopped\n        if col2 == \"RUNNING\" then\n            status = status .. '<td style=\"background-color:DarkGreen\">'\n        end\n        if col2 == \"JAMMED_MISSING_INGREDIENT\" then\n            status = status .. '<td style=\"background-color:tomato\">'\n        end\n        if col2 == \"JAMMED_OUTPUT_FULL\" then\n            status = status .. '<td style=\"background-color:tomato\">'\n        end\n        if col2 == \"JAMMED_NO_OUTPUT_CONTAINER\" then\n            status = status .. '<td style=\"background-color:tomato\">'\n        end\n\n        col3 = slots[i][3]\n        col3 = round(col3, 0)\n        col4 = round((slots[i][4] * 100),1)\n        col5 = slots[i][5]\n\n        if col2 == \"STOPPED\" then\n            status = status .. '<td style=\"background-color:orange\">'\n            col3 = '-'\n            col4 = '-'\n            col5 = '-'\n        end\n        \n        if col2 == \"PENDING\" then\n            status = status .. '<td style=\"background-color:orange\">'\n            col3 = '-'\n            col4 = '-'\n            col5 = '-'\n        end\n        --name td\n        local name = '<td>' .. col1 .. '</td>'\n        --status td\n        local status = status .. col2 .. '</td>' \n        --uptime td\n        local uptime = '<td>' .. col3 .. '</td>'\n        --efficiency td\n        local eff = '<td>' .. col4 .. '</td>'\n        --count td\n        local count = '<td>' .. col5 .. '</td>'\n\n\n        dispHtml = dispHtml .. name .. status .. uptime .. eff .. count .. '</tr>'\n    end    \nend\n\nlocal finalHtml = beginHtml .. dispHtml .. endHtml\n\nscreen.setHTML(finalHtml)","filter":{"args":[{"value":"refresh"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"4"},{"code":"screen.activate()","filter":{"args":[],"signature":"start()","slotKey":"-2"},"key":"5"},{"code":"screen.deactivate()","filter":{"args":[],"signature":"stop()","slotKey":"-2"},"key":"6"}],"methods":[],"events":[]}

In-game, right click the programming board > Advanced > Paste lua config from clipboard

 

Link from the programming board to your base core
Link from the board to your screen

Link from your board to an industry unit, up to 8 of them

 

Activate the programming board

 

Updates:

26 Sep - Added some logic to account for Pending status of the machines

Share this post


Link to post
Share on other sites

This looks awesome but states "Script Error!" when I try to run it. Have repeated the steps 3 times now and still same issue. Any obvious thing i may have overlooked when following these instructions? I have zero LUA knowledge so have no expectations of a resolution. When I activate the board the screen comes on (decreasing circles display) but bottom right states script error.

 

When you say "Access to your base core (for linking purposes)" do i need to do anything other than link using 6 key? It is my personal core so assume i dont have to grant anything.

 

Suggestions?

Share this post


Link to post
Share on other sites

OK so the line that is erroring is in the unit tick(refresh) script line 3

 

number = string.format(fmtStr,number)

 

Error says "bad argument #2 to 'format'(number expected, got nil)

 

Also the LUA console states the following:

 

Warning: method getElementName is deprecated, use getElementNameByID instead

Warning: method getElementHitPoints is deprecated, use getElementHitPointsByID instead

Warning: method getElementMaxHitPoints is deprecated, use getElementMaxHitPointsByID instead

Warning: method getElementMass is deprecated, use getElementMassByID instead

Warning: method getElementType is deprecated, use getElementTypeByID instead

 

 

Share this post


Link to post
Share on other sites

This may work better - I have copied the config from a proven working programming board - CTRL + C all this code, then in game right click the programming board > advanced > Paste lua config from clipboard.

 

Also to note, if you didn't link the items in the correct order, these boards can be finnicky and you may have to create a new board and try it with a fresh one:

 

{"slots":{"0":{"name":"core","type":{"events":[],"methods":[]}},"1":{"name":"screen","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"screen.setHTML([[\n    <svg width=\"100vw\" height=\"60vw\" viewBox=\"0 0 45 45\" xmlns=\"http://www.w3.org/2000/svg\" stroke=\"#fff\">\n    <g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\" stroke-width=\"2\">\n        <circle cx=\"22\" cy=\"22\" r=\"6\" stroke-opacity=\"0\">\n            <animate attributeName=\"r\"\n                 begin=\"1.5s\" dur=\"3s\"\n                 values=\"6;22\"\n                 calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n            <animate attributeName=\"stroke-opacity\"\n                 begin=\"1.5s\" dur=\"3s\"\n                 values=\"1;0\" calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n            <animate attributeName=\"stroke-width\"\n                 begin=\"1.5s\" dur=\"3s\"\n                 values=\"2;0\" calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n        </circle>\n        <circle cx=\"22\" cy=\"22\" r=\"6\" stroke-opacity=\"0\">\n            <animate attributeName=\"r\"\n                 begin=\"3s\" dur=\"3s\"\n                 values=\"6;22\"\n                 calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n            <animate attributeName=\"stroke-opacity\"\n                 begin=\"3s\" dur=\"3s\"\n                 values=\"1;0\" calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n            <animate attributeName=\"stroke-width\"\n                 begin=\"3s\" dur=\"3s\"\n                 values=\"2;0\" calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n        </circle>\n        <circle cx=\"22\" cy=\"22\" r=\"8\">\n            <animate attributeName=\"r\"\n                 begin=\"0s\" dur=\"1.5s\"\n                 values=\"6;1;2;3;4;5;6\"\n                 calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n        </circle>\n    </g>\n</svg>\n    ]])","filter":{"args":[],"signature":"start()","slotKey":"1"},"key":"0"},{"code":"screen.clear","filter":{"args":[],"signature":"stop()","slotKey":"1"},"key":"1"},{"code":"unit.setTimer(\"loading\", 5)","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"2"},{"code":"unit.setTimer(\"refresh\", 1)\nunit.stopTimer(\"loading\")","filter":{"args":[{"value":"loading"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"3"},{"code":"function round(number, precision)\n    local fmtStr = string.format('%%0.%sf',precision)\n    number = string.format(fmtStr,number)\n    return number\nend\n\nslots = {}\nif slot3 then \n    table.insert(slots,{slot3.getId(),slot3.getStatus(),slot3.getUptime(),slot3.getEfficiency(),slot3.getCycleCountSinceStartup()})\nend\nif slot4 then\n    table.insert(slots,{slot4.getId(),slot4.getStatus(),slot4.getUptime(),slot4.getEfficiency(),slot4.getCycleCountSinceStartup()})\nend\nif slot5 then\n    table.insert(slots,{slot5.getId(),slot5.getStatus(),slot5.getUptime(),slot5.getEfficiency(),slot5.getCycleCountSinceStartup()})\nend\nif slot6 then\n    table.insert(slots,{slot6.getId(),slot6.getStatus(),slot6.getUptime(),slot6.getEfficiency(),slot6.getCycleCountSinceStartup()})\nend\nif slot7 then\n    table.insert(slots,{slot7.getId(),slot7.getStatus(),slot7.getUptime(),slot7.getEfficiency(),slot7.getCycleCountSinceStartup()})\nend\nif slot8 then\n    table.insert(slots,{slot8.getId(),slot8.getStatus(),slot8.getUptime(),slot8.getEfficiency(),slot8.getCycleCountSinceStartup()})\nend\nif slot9 then\n    table.insert(slots,{slot9.getId(),slot9.getStatus(),slot9.getUptime(),slot9.getEfficiency(),slot9.getCycleCountSinceStartup()})\nend\nif slot10 then\n    table.insert(slots,{slot10.getId(),slot10.getStatus(),slot10.getUptime(),slot10.getEfficiency(),slot10.getCycleCountSinceStartup()})\nend\nlocal beginHtml = [[\n    <style>table{width:100%;font-size:19px;color:#99CC00;border-collapse:collapse;}td{width:20vw;border-bottom: 1px solid;text-align:center}tr{height: 60px}</style>\n    <body style=\"width:100%\">\n    <table>\n        <tr style=\"font-weight:bold;align-text:center;background-color:indigo;\">\n            <td>Machine</td>\n            <td>Status</td>\n            <td>Uptime(sec)</td>\n            <td>Efficiency</td>\n            <td>Cycle Count</td>\n        </tr>\n]]\nlocal endHtml = [[\n\t\n    </table>\n\t<tr>v1.0 // created by: injurytoall</tr>\n    </body>\n]]\nlocal dispHtml = '<tr>'\nfor i = 0,8 do\n    if slots[i] == nil then\n    else\n        local id = slots[i][1]\n        local col1 = database.getElement(core, id).name\n         \t\n        --status\n        local col2 = slots[i][2]\n        --uptime\n        local col3 = ''\n        local col4 = ''\n        local col5 = ''\n\n        local status = ''\n        --if machine is stopped\n        if col2 == \"RUNNING\" then\n            status = status .. '<td style=\"background-color:DarkGreen\">'\n        end\n        if col2 == \"JAMMED_MISSING_INGREDIENT\" then\n            status = status .. '<td style=\"background-color:tomato\">'\n        end\n        if col2 == \"JAMMED_OUTPUT_FULL\" then\n            status = status .. '<td style=\"background-color:tomato\">'\n        end\n        if col2 == \"JAMMED_NO_OUTPUT_CONTAINER\" then\n            status = status .. '<td style=\"background-color:tomato\">'\n        end\n\n        col3 = slots[i][3]\n        col3 = round(col3, 0)\n        col4 = round((slots[i][4] * 100),1)\n        col5 = slots[i][5]\n\n        if col2 == \"STOPPED\" then\n            status = status .. '<td style=\"background-color:orange\">'\n            col3 = '-'\n            col4 = '-'\n            col5 = '-'\n        end\n        --name td\n        local name = '<td>' .. col1 .. '</td>'\n        --status td\n        local status = status .. col2 .. '</td>' \n        --uptime td\n        local uptime = '<td>' .. col3 .. '</td>'\n        --efficiency td\n        local eff = '<td>' .. col4 .. '</td>'\n        --count td\n        local count = '<td>' .. col5 .. '</td>'\n\n\n        dispHtml = dispHtml .. name .. status .. uptime .. eff .. count .. '</tr>'\n    end    \nend\n\nlocal finalHtml = beginHtml .. dispHtml .. endHtml\n\nscreen.setHTML(finalHtml)","filter":{"args":[{"value":"refresh"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"4"},{"code":"screen.activate()","filter":{"args":[],"signature":"start()","slotKey":"-2"},"key":"5"},{"code":"screen.deactivate()","filter":{"args":[],"signature":"stop()","slotKey":"-2"},"key":"6"}],"methods":[],"events":[]}

 

Share this post


Link to post
Share on other sites
1 hour ago, injurytoall said:

This may work better - I have copied the config from a proven working programming board - CTRL + C all this code, then in game right click the programming board > advanced > Paste lua config from clipboard.

 

Also to note, if you didn't link the items in the correct order, these boards can be finnicky and you may have to create a new board and try it with a fresh one:

 


{"slots":{"0":{"name":"core","type":{"events":[],"methods":[]}},"1":{"name":"screen","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"screen.setHTML([[\n    <svg width=\"100vw\" height=\"60vw\" viewBox=\"0 0 45 45\" xmlns=\"http://www.w3.org/2000/svg\" stroke=\"#fff\">\n    <g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\" stroke-width=\"2\">\n        <circle cx=\"22\" cy=\"22\" r=\"6\" stroke-opacity=\"0\">\n            <animate attributeName=\"r\"\n                 begin=\"1.5s\" dur=\"3s\"\n                 values=\"6;22\"\n                 calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n            <animate attributeName=\"stroke-opacity\"\n                 begin=\"1.5s\" dur=\"3s\"\n                 values=\"1;0\" calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n            <animate attributeName=\"stroke-width\"\n                 begin=\"1.5s\" dur=\"3s\"\n                 values=\"2;0\" calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n        </circle>\n        <circle cx=\"22\" cy=\"22\" r=\"6\" stroke-opacity=\"0\">\n            <animate attributeName=\"r\"\n                 begin=\"3s\" dur=\"3s\"\n                 values=\"6;22\"\n                 calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n            <animate attributeName=\"stroke-opacity\"\n                 begin=\"3s\" dur=\"3s\"\n                 values=\"1;0\" calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n            <animate attributeName=\"stroke-width\"\n                 begin=\"3s\" dur=\"3s\"\n                 values=\"2;0\" calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n        </circle>\n        <circle cx=\"22\" cy=\"22\" r=\"8\">\n            <animate attributeName=\"r\"\n                 begin=\"0s\" dur=\"1.5s\"\n                 values=\"6;1;2;3;4;5;6\"\n                 calcMode=\"linear\"\n                 repeatCount=\"indefinite\" />\n        </circle>\n    </g>\n</svg>\n    ]])","filter":{"args":[],"signature":"start()","slotKey":"1"},"key":"0"},{"code":"screen.clear","filter":{"args":[],"signature":"stop()","slotKey":"1"},"key":"1"},{"code":"unit.setTimer(\"loading\", 5)","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"2"},{"code":"unit.setTimer(\"refresh\", 1)\nunit.stopTimer(\"loading\")","filter":{"args":[{"value":"loading"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"3"},{"code":"function round(number, precision)\n    local fmtStr = string.format('%%0.%sf',precision)\n    number = string.format(fmtStr,number)\n    return number\nend\n\nslots = {}\nif slot3 then \n    table.insert(slots,{slot3.getId(),slot3.getStatus(),slot3.getUptime(),slot3.getEfficiency(),slot3.getCycleCountSinceStartup()})\nend\nif slot4 then\n    table.insert(slots,{slot4.getId(),slot4.getStatus(),slot4.getUptime(),slot4.getEfficiency(),slot4.getCycleCountSinceStartup()})\nend\nif slot5 then\n    table.insert(slots,{slot5.getId(),slot5.getStatus(),slot5.getUptime(),slot5.getEfficiency(),slot5.getCycleCountSinceStartup()})\nend\nif slot6 then\n    table.insert(slots,{slot6.getId(),slot6.getStatus(),slot6.getUptime(),slot6.getEfficiency(),slot6.getCycleCountSinceStartup()})\nend\nif slot7 then\n    table.insert(slots,{slot7.getId(),slot7.getStatus(),slot7.getUptime(),slot7.getEfficiency(),slot7.getCycleCountSinceStartup()})\nend\nif slot8 then\n    table.insert(slots,{slot8.getId(),slot8.getStatus(),slot8.getUptime(),slot8.getEfficiency(),slot8.getCycleCountSinceStartup()})\nend\nif slot9 then\n    table.insert(slots,{slot9.getId(),slot9.getStatus(),slot9.getUptime(),slot9.getEfficiency(),slot9.getCycleCountSinceStartup()})\nend\nif slot10 then\n    table.insert(slots,{slot10.getId(),slot10.getStatus(),slot10.getUptime(),slot10.getEfficiency(),slot10.getCycleCountSinceStartup()})\nend\nlocal beginHtml = [[\n    <style>table{width:100%;font-size:19px;color:#99CC00;border-collapse:collapse;}td{width:20vw;border-bottom: 1px solid;text-align:center}tr{height: 60px}</style>\n    <body style=\"width:100%\">\n    <table>\n        <tr style=\"font-weight:bold;align-text:center;background-color:indigo;\">\n            <td>Machine</td>\n            <td>Status</td>\n            <td>Uptime(sec)</td>\n            <td>Efficiency</td>\n            <td>Cycle Count</td>\n        </tr>\n]]\nlocal endHtml = [[\n\t\n    </table>\n\t<tr>v1.0 // created by: injurytoall</tr>\n    </body>\n]]\nlocal dispHtml = '<tr>'\nfor i = 0,8 do\n    if slots[i] == nil then\n    else\n        local id = slots[i][1]\n        local col1 = database.getElement(core, id).name\n         \t\n        --status\n        local col2 = slots[i][2]\n        --uptime\n        local col3 = ''\n        local col4 = ''\n        local col5 = ''\n\n        local status = ''\n        --if machine is stopped\n        if col2 == \"RUNNING\" then\n            status = status .. '<td style=\"background-color:DarkGreen\">'\n        end\n        if col2 == \"JAMMED_MISSING_INGREDIENT\" then\n            status = status .. '<td style=\"background-color:tomato\">'\n        end\n        if col2 == \"JAMMED_OUTPUT_FULL\" then\n            status = status .. '<td style=\"background-color:tomato\">'\n        end\n        if col2 == \"JAMMED_NO_OUTPUT_CONTAINER\" then\n            status = status .. '<td style=\"background-color:tomato\">'\n        end\n\n        col3 = slots[i][3]\n        col3 = round(col3, 0)\n        col4 = round((slots[i][4] * 100),1)\n        col5 = slots[i][5]\n\n        if col2 == \"STOPPED\" then\n            status = status .. '<td style=\"background-color:orange\">'\n            col3 = '-'\n            col4 = '-'\n            col5 = '-'\n        end\n        --name td\n        local name = '<td>' .. col1 .. '</td>'\n        --status td\n        local status = status .. col2 .. '</td>' \n        --uptime td\n        local uptime = '<td>' .. col3 .. '</td>'\n        --efficiency td\n        local eff = '<td>' .. col4 .. '</td>'\n        --count td\n        local count = '<td>' .. col5 .. '</td>'\n\n\n        dispHtml = dispHtml .. name .. status .. uptime .. eff .. count .. '</tr>'\n    end    \nend\n\nlocal finalHtml = beginHtml .. dispHtml .. endHtml\n\nscreen.setHTML(finalHtml)","filter":{"args":[{"value":"refresh"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"4"},{"code":"screen.activate()","filter":{"args":[],"signature":"start()","slotKey":"-2"},"key":"5"},{"code":"screen.deactivate()","filter":{"args":[],"signature":"stop()","slotKey":"-2"},"key":"6"}],"methods":[],"events":[]}

 

That works a treat THANKS!

 

Is there anyway to reduce the impact of the screen refreshing? Every second it flickers (I assume when it is refreshing?). On my (in game) screen its quite significant (and annoying). Or is that something to put up with.

 

Great work btw and thanks for sharing.

Share this post


Link to post
Share on other sites

For anyone experiencing the refresh flash I have amended my unit loading tick to the following. Means the screens are only refreshed every 10 seconds but thats not an issue for me and it stops the annoyance of the screen flickering every second.

 

unit.setTimer("refresh", 10)
unit.stopTimer("loading")

 

If there is a workaround to decrease the flicker then great, let me know, otherwise THANK YOU SO MUCH AGAIN!

Share this post


Link to post
Share on other sites

Hey injurytoall, almost everything is working now. However, I have found an issue where the Status column is omitted on the screen if the situation of the machine is in a status of Pending due to the "Maintain" volume being reached. Is there a "If" statement that can be added for this scenario? 

Share this post


Link to post
Share on other sites

Ah yes. I had fixed that locally on an installation at an org mate's machine and didn't update my code -- Fix has been added to the original post.

 

You can manually add it if you'd like too. Just after the if for stopped

        if col2 == "PENDING" then
            status = status .. '<td style="background-color:orange">'
            col3 = '-'
            col4 = '-'
            col5 = '-'
        end

Share this post


Link to post
Share on other sites

OK, no biggie if not but do you have a script that will monitor the volume of a certain material (i.e. Coal) in a certain container? The idea being I can display the quantity I have on a screen so I know when to top up. If I have above a certain value then green background, if I am running below a certain value then amber, and red if out. Cheeky to ask here rather than a new thread I know but worth a shot.

Share this post


Link to post
Share on other sites

 

You can't query a container for it's contents sadly. You could however say container x contains a specific resource (eg. Coal) and then do all the calculations with the assumption that container only has coal in it. I don't have any scripts for that. I was doing some work on a fuel display next for others to see besides the pilot, but a nice one was posted to this board.

I wanted to display the current item being processed and the time left for completion, but you cannot access that information from the API.

 

I may revisit this script in the future as I had some ideas about including some touch features for starting/stopping machines which can be done via the API.

Share this post


Link to post
Share on other sites

Thank you, This worked like a charm - thank you.  Is the intermittent screen flash normal?  And is there a way to stop the screen contents enlarging from a distance.

Thirdly, sorry :D  Do you have a script that you can show content totals of 8 boxes for one screen?  With an alert (colour) if they fall beneath a specified amount?

 

Thanks again, first script I got working.

Share this post


Link to post
Share on other sites
52 minutes ago, virtualburn said:

Thank you, This worked like a charm - thank you.  Is the intermittent screen flash normal?  And is there a way to stop the screen contents enlarging from a distance.

Thirdly, sorry :D  Do you have a script that you can show content totals of 8 boxes for one screen?  With an alert (colour) if they fall beneath a specified amount?

 

Thanks again, first script I got working.

Pretty sure all of these questions have been asked and answered above...

Share this post


Link to post
Share on other sites
6 minutes ago, CreditCain said:

Pretty sure all of these questions have been asked and answered above...

They certainly have, must be selective reading.

Thanks.

Share this post


Link to post
Share on other sites

First off thanks for this script. I have an odd issue with it. I have an odd issue after a period of time the display is almost like its zoomed in? Example I have 6 factorys and can see them all after some time I can only see about 4 of them and all the fonts seam larger?

Any suggestions I should try?

Share this post


Link to post
Share on other sites

If the screen ever gets wonky, just turn off the programming board and turn it back on. It is not saving any information, it simply updates the view every second.

You can get rid of the loading screen too if you want by editing the start() filter in the unit. Change

unit.setTimer("loading"5) -> unit.setTimer("loading", 1)

It is only there for fluff really.

Share this post


Link to post
Share on other sites

I actually have this same "zooming" issue with almost all of the LUA scripts I use.  I've switched to using specific point font sizes and custom SVG and so far (fingers crossed) my other scripts don't have this problem.  Sadly, they aren't very complex either, so if anyone comes up with a solution to this bug please fire it over.  Restarting the board doesn't do anything thus far, and sometimes even relogging fails to clear it.

 

Thoughts?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...