Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Leutech

Help with function

Question

Greetings dear opencomputers community.

 

I have a problem with my script for my ic2 fluid reactor.

I have a function to call all fuel rods in the fluid reactor over the inventory controller and it works fine but i want to add color to the current state of the damage of each rod and i have the following function for this.

This is my test.lua

local component = require("component")
local term = require("term")
local gpu = component.gpu
local ic = component.inventory_controller
local rc = component.reactor_chamber

local function getDur( frvari, frslot, frdmg, frmaxdmg, frc )
	local frvari = ic.getStackInSlot( SIDE, frslot )
  	local frc = "0xFFFFFF"
  	frdmg = frvari.damage
  	frmaxdmg = frvari.maxDamage
  	if frdmg == 0 then
    	frc = "0x008421"
	elseif frdmg > 0 and frdmg < 2500 then
		frc = "0x00FF00"
	elseif frdmg >= 2500 and frdmg < 5000 then
		frc = "0xFFFF00"
	elseif frdmg >= 5000 and frdmg < 7500 then
		frc = "0xFFA800"
	elseif frdmg >= 7500 and frdmg < 10000 then
		frc = "0xFF6D00"
	elseif frdmg >= 10000 and frdmg < 12500 then
		frc = "0xFF3A00"
	elseif frdmg >= 12500 and frdmg < 15000 then
		frc = "0xFF2B00"
	elseif frdmg >= 15000 and frdmg < 17500 then
		frc = "0xFF0000"
	elseif frdmg >= 17500 and frdmg < 20000 then
		frc = "0x970000"
	end
end

getDur( FR1, 21, FR1D, FR1MD, FR1C )
getDur( FR2, 25, FR2D, FR2MD, FR2C )
getDur( FR3, 30, FR3D, FR3MD, FR3C )
getDur( FR4, 34, FR4D, FR4MD, FR4C )

print(FR1D, FR1MD, FR1C)
print(FR2D, FR2MD, FR2C)
print(FR3D, FR3MD, FR3C)
print(FR4D, FR4MD, FR4C)

 

And if i execute the script he show me this:

2020-07-08_10_50_49.thumb.png.ee2ee7c4c67f24eadf0579530e9cc888.png

 

He show me a "nil" value but he should print me a string like this "0xFFA800" or like this "0x970000". What im doing wrong?

Share this post


Link to post
Share on other sites

34 answers to this question

Recommended Posts

  • 0

This does not look like the actual script you are running, I don't see any variable (like FR1D, FR1MD) etc that is getting declared.

Also, are you trying to pass some variable (FR1C for example) to the getDur function and expect it to set the value of this variable to the color? Because that does not work, since the parameters to a function are local, you could manipulate a global value, pass a table to the function and set a color attribute of the table or simply return some values.

It would help if you could share the actual script, and then I am able to help you solve your problem.

Share this post


Link to post
Share on other sites
  • 0
6 hours ago, Leutech said:

I have send the scripts as attachment.

reactor.lua 7.47 kB · 1 download adWrite.lua 1.08 kB · 1 download

@CptMercury the variables are decalred by the function itself. If i call the function i delacre there variables and its work but not with last argument.

The variables are NOT declared. You are calling those functions with undeclared variables which basically means you give it "nil".

I recommend you change this:

getDuriUH( UH01, 1, UH01D, UH01MD, UH01C )

to this:

local UH01, UH01D, UH01MD, UH01C = getDuriUH(1)

and this:

function getDuriUH(uhvari, uhslot, uhdmg, uhmaxdmg, uhdmgColor)
  local uhvari = ic.getStackInSlot(3, uhslot)
  local uhdmg = uhvari.damage
  local uhmaxdmg = uhvari.maxDamage
  local uhdmgColor = "0xFFFFFF"
  if uhdmg == 0 then
    uhdmgColor = "0x008421"
  elseif uhdmg > 0 and uhdmg < 125 then
    uhdmgColor = "0x00FF00"
  elseif uhdmg >= 125 and uhdmg < 250 then
    uhdmgColor = "0xFFFF00"
  elseif uhdmg >= 250 and uhdmg < 375 then
    uhdmgColor = "0xFFA800"
  elseif uhdmg >= 375 and uhdmg < 500 then
    uhdmgColor = "0xFF6D00"
  elseif uhdmg >= 500 and uhdmg < 625 then
    uhdmgColor = "0xFF3A00"
  elseif uhdmg >= 625 and uhdmg < 750 then
    uhdmgColor = "0xFF2B00"
  elseif uhdmg >= 750 and uhdmg < 875 then
    uhdmgColor = "0xFF0000"
  elseif uhdmg >= 825 and uhdmg < 1000 then
    uhdmgColor = "0x970000"
  end
end

to this:

local function getDuriUH(uhslot)
  local uhvari     = ic.getStackInSlot(3, uhslot)
  local uhdmg      = uhvari.damage
  local uhmaxdmg   = uhvari.maxDamage
  local uhdmgColor = "0xFFFFFF"

  if uhdmg <= 0 then
    uhdmgColor = "0x008421"
  elseif uhdmg < 125 then
    uhdmgColor = "0x00FF00"
  elseif uhdmg < 250 then
    uhdmgColor = "0xFFFF00"
  elseif uhdmg < 375 then
    uhdmgColor = "0xFFA800"
  elseif uhdmg < 500 then
    uhdmgColor = "0xFF6D00"
  elseif uhdmg < 625 then
    uhdmgColor = "0xFF3A00"
  elseif uhdmg < 750 then
    uhdmgColor = "0xFF2B00"
  elseif uhdmg < 875 then
    uhdmgColor = "0xFF0000"
  elseif uhdmg < 1000 then
    uhdmgColor = "0x970000"
  end

  return uhvari, uhdmg, uhmaxdmg, uhdmgColor
end

 

Have you noticed how getDuriUH(), getDuriKW() and getDuriBS() are the same? You could just make them into 1 function and then divide the damage for KW by 5 and for BS by 20.

But seriously those 50 lines were you basically just call the same function with a different interger... use a loop and a table.

 

Share this post


Link to post
Share on other sites
  • 0

@Nexarius thank you for your reply i test it now but i cant do this for all because they have different maxDamage. I explain you:

The "Overclocked Heat Vent" has a maxDamage of "1000".

The "Component Heat Exchanger" has a maxDamage of "5000".

And the "Quad Fuel Rod (Uranium)" has a maxDamage of "20000".

So i can't do this in one function.

Because i want the color of the percentage amount of the damage that are taken.

Share this post


Link to post
Share on other sites
  • 0

Okay i have test it now and now he print me the correct color code. And can you help me to put the massive things in a loop with one function of the percentage of the maxDamage of the right component?

Share this post


Link to post
Share on other sites
  • 0
21 minutes ago, Leutech said:

Okay i have test it now and now he print me the correct color code. And can you help me to put the massive things in a loop with one function of the percentage of the maxDamage of the right component?

I've made some improvements. Its combined with a single function and they are called from a loop and the results are then stored in a table.
It doesn't matter that they have differente maxdmg values because you have the dmg and the maxdmg and can easily calculate the percentage.

Have fun with it.

local component = require("component")
local computer  = require("computer")
local term      = require("term")
local aw        = require("adWrite")

local gp        = component.proxy(component.get("6fa6e9ed"))
local rc        = component.proxy(component.get("c3f546da"))
local ic        = component.proxy(component.get("2a60f6e0"))
local tr        = component.proxy(component.get("7621f0f8"))

local rslamps   = component.proxy(component.get("61d91131"))
local rsreactor = component.proxy(component.get("a0a9b4d3"))

local colors = {
    green  = 0x00FF00,
    yellow = 0xFFFF00,
    orange = 0xFFA800,
    black  = 0x000000,
    white  = 0xFFFFFF,
    red    = 0xFF0000,
    blue   = 0x0000FF,
    cyan   = 0x00FFFF
}

function write(zeile, spalte, ...)
    term.setCursor(spalte, zeile)
    aw.write(...)
end

function centerF(row, msg, ...)
    local mLen = string.len(msg)
    w, h = gp.getResolution()
    term.setCursor((w - mLen)/2, row)
    print(msg:format(...))
end

gp.setResolution(67, 24)

term.clear()
term.setCursor(1 ,1)

local function getDuri(slot)
    local vari     = ic.getStackInSlot(3, slot)
    local dmg      = vari.damage
    local maxdmg   = vari.maxDamage
    local dmgColor = "0xFFFFFF"
    local prozent  = dmg / maxdmg

    if prozent <= 0 then
        dmgColor = "0x008421"
    elseif prozent < 12.5 then
        dmgColor = "0x00FF00"
    elseif prozent < 25 then
        dmgColor = "0xFFFF00"
    elseif prozent < 37.5 then
        dmgColor = "0xFFA800"
    elseif prozent < 50 then
        dmgColor = "0xFF6D00"
    elseif prozent < 62.5 then
        dmgColor = "0xFF3A00"
    elseif prozent < 75 then
        dmgColor = "0xFF2B00"
    elseif prozent < 87.5 then
        dmgColor = "0xFF0000"
    else
        dmgColor = "0x970000"
    end

    return {vari, dmg, maxdmg, dmgColor}
end

local makepadding(text, max) -- return empty charaters with max length but minus the lenght of the text / number input
    local lang = string.len(tostring(text)) - max
    if lang < 0 then
        return ""
    else
        return string.rep(" ", lang)
    end
end

while true do
    gp.setBackground(colors.black)

    local UH = {} -- this table is for all UH
    for _, slot in pairs({1, 2, 4, 5, 6, 8, 9, 12, 16, 19, 20, 22, 23, 24, 26, 27, 28, 29, 31, 32, 33, 35, 36, 39, 43, 46, 47, 49, 50, 51, 53, 54}) do -- go over all slots
        table.insert(UH, getDuri(slot)) -- filling the table
    end

    local KW = {}
    for _, slot in pairs({10, 11, 13, 14, 15, 17, 18, 37, 38, 40, 41, 42, 44, 45}) do
        table.insert(KW, getDuri(slot))
    end

    local BS = {}
    for _, slot in pairs({21, 25, 30, 34}) do
        table.insert(UH, getDuri(slot))
    end

    gp.setForeground(colors.orange)
    centerF(2, string.rep("-", 51))
    centerF(3, "-----               Atomreaktor               -----")
    centerF(4, string.rep("-", 51))
    gp.setForeground(colors.green)
    centerF(6, string.format("Brennstäbe"))

    local BS1S = makepadding(BS[1][2], 7) --BS[1][2] access first entry and then the 2 value (which is dmg)
    local BS2S = makepadding(BS[2][2], 7) -- I hope I understood correctly how those values are generated
    local BS3S = makepadding(BS[3][2], 7)
    local BS4S = makepadding(BS[4][2], 7)

    term.setCursor(2, 7)
    aw.write(string.format("1:" ..BS1S.. "<color fg=" ..BS1C.. ">" ..BS1D.. "</color>/" ..BS1MD.. " | 2:" ..BS2S.. "<color fg=" ..BS2C.. ">" ..BS2D.. "</color>/" ..BS2MD.. " | 3:" ..BS3S.. "<color fg=" ..BS3C.. ">" ..BS3D.. "</color>/" ..BS3MD))

    os.sleep(1)
end

Btw what's with those <color> tags?

Share this post


Link to post
Share on other sites
  • 0

Okay thanks i will try it and for your question with the "<color>" with him i can do this:

2020-07-09_01_36_48.thumb.png.f1c4c0f8ad527e5e57e827ed5f4e99a3.png

The script there i use "adWrite" is from here:

 

Share this post


Link to post
Share on other sites
  • 0
4 minutes ago, Leutech said:

Okay thanks i will try it and for your question with the "<color>" with him i can do this:

2020-07-09_01_36_48.thumb.png.f1c4c0f8ad527e5e57e827ed5f4e99a3.png

The script there i use "adWrite" is from here:

 

That's cool :)

Share this post


Link to post
Share on other sites
  • 0

Ok i have a see a mistake from you :D with the operation to get the percentage if i use this i get always a percentage of 0..... because the damage is never over the maxDamage so i cant do "dmg / maxdmg" i can use only "dmg * 100 / maxdmg" ^^

Share this post


Link to post
Share on other sites
  • 0

Okay if i want to start the script he says me "/lib/process.lua:52: /home/reactor.lua:72: ')' expected near ',':"

Share this post


Link to post
Share on other sites
  • 0
4 hours ago, Leutech said:

Ok i have a see a mistake from you :D with the operation to get the percentage if i use this i get always a percentage of 0..... because the damage is never over the maxDamage so i cant do "dmg / maxdmg" i can use only "dmg * 100 / maxdmg" ^^

Ah yes of course :D

3 hours ago, Leutech said:

Okay if i want to start the script he says me "/lib/process.lua:52: /home/reactor.lua:72: ')' expected near ',':"

oopps

This here:

local makepadding(text, max)

of course has to be:

local function makepadding(text, max)

 

It's also probably better if you try:

local ic = component.getPrimary("inventory_controller")

instead of:

local ic = component.proxy(component.get("2a60f6e0"))

if you want to use the program in the future in a new computer and don't want to change all the component addresses.
As long as you don't want to access 2 of the same component type you don't need to do it with component.proxy.

Share this post


Link to post
Share on other sites
  • 0

Ok thanks i dont habe see this wirh the function i test iz later if i back at home. And yeah i know but its look for me better if i call the component directly over his address. But thanks for the other solution i keep it in mind.

Share this post


Link to post
Share on other sites
  • 0

I'm sorry I couldn't get back to you sooner, but I saw @Nexarius was helping you out.

On 7/8/2020 at 6:23 PM, Leutech said:

@CptMercury the variables are decalred by the function itself. If i call the function i delacre there variables and its work but not with last argument.

As Nexarius has pointed out, your function doesn't declare these variables. I sadly can't open the files you posted, it seems as they are no longer available, but I took the file Nexarius posted as a starting point. There I still see variables that are not declared (BS1C, BS1D, BS1MD, BS2C, BS2D, BS2MD, BS3C, BS3D, BS3MD)

16 hours ago, Nexarius said:

aw.write(string.format("1:" ..BS1S.. "<color fg=" ..BS1C.. ">" ..BS1D.. "</color>/" ..BS1MD.. " | 2:" ..BS2S.. "<color fg=" ..BS2C.. ">" ..BS2D.. "</color>/" ..BS2MD.. " | 3:" ..BS3S.. "<color fg=" ..BS3C.. ">" ..BS3D.. "</color>/" ..BS3MD))

I assume these stand for color (BS1C), damage (BS1D) and max damage (BS1MD), am I correct? But what is the BS1S etc for? From the script it looks like it is the damage swell, but I'm not sure.

If you could tell more details about what your code does, I can help you to make it even better, I already have some good ideas. (If you want to share code again, please add the code to the reply like Nexarius and I are doing)

Anyways, I already took the code and modified it to some extend, always commenting what changes I made and why. (In terms of the undeclared variables, I used the values for color, damage and max damage and removed the first values BS1S, BS2S and BS3S since I couldn't figure out, what they should represent, and I also didn't do the padding, but it's no big deal to add that later)

local component = require("component")
local computer  = require("computer")
local term      = require("term")
local aw        = require("adWrite")

-- component.<component name> is equal to component.getPrimary(<component name>)
-- just looks a bit clearer
-- might be a good way to handle the following 3 components aswell
local ic        = component.inventory_controller
local gp        = component.proxy(component.get("6fa6e9ed"))
local rc        = component.proxy(component.get("c3f546da"))
local tr        = component.proxy(component.get("7621f0f8"))

local rslamps   = component.proxy(component.get("61d91131"))
local rsreactor = component.proxy(component.get("a0a9b4d3"))

local colors = {
  green  = 0x00FF00,
  yellow = 0xFFFF00,
  orange = 0xFFA800,
  black  = 0x000000,
  white  = 0xFFFFFF,
  red    = 0xFF0000,
  blue   = 0x0000FF,
  cyan   = 0x00FFFF
}

-- aw.write takes only one parameter, so using varargs doens't help you
-- also, that way your intention is clearer
function write(zeile, spalte, str)
  term.setCursor(spalte, zeile)
  aw.write(str)
end

-- here, you don't even have more that 2 arguments, so leave the vararg part
function centerF(row, str)
  -- you only need the width, so don't bother getting the height
  w = gp.getResolution()
  -- using the # operator is faster than using string.len
  term.setCursor((w - #str)/2, row)
  -- first, don't use string.format here because you are not formatting anything
  -- so that would be a waste of time
  -- second, I would use term.write or io.write instead of print
  -- but print adds a newline following the string, so if you really want that,
  -- add a newline: term.write(str, "\n")
  term.write(str)
end

gp.setResolution(67, 24)

term.clear()
term.setCursor(1 ,1)

-- colors are numbers now, not strings, but if you really want them to be
-- strings, thats possible aswell
local dmg_colors = {[0] =
  0x008421,
  0x00FF00,
  0xFFFF00,
  0xFFA800,
  0xFF6D00,
  0xFF3A00,
  0xFF2B00,
  0xFF2B00,
  0xFF0000
}

-- This is a faster and slightly more readable function than the original one.
-- instead of using long elseif using a look-up table is often the better option
-- here I am scaling the damage to a number between 0-8, using math.ceil
-- and then using the number to get the correct color from the table
-- the last color you had in the final else statement would have never been
-- reached, therefore i left it
local function getDuri(slot)
  local item     = ic.getStackInSlot(3, slot)
  local dmg      = item.damage
  local maxdmg   = item.maxDamage
  local prozent = math.ceil(dmg / maxdmg * 8)

  local dmgColor = dmg_colors[prozent]
  return {item, dmg, maxdmg, dmgColor}
end


-- this will do the same as your previous function; string.rep(str, n) will
-- return an empty string when n is < 1
local function makepadding(text, max)
  return string.rep(" ", #tostring(text) - max)
end

-- I moved the tables form the pairs function outside of the loop to prevent
-- creation of 3 new tables each time; this is more efficient
local UH_slots = {
  1, 2, 4, 5, 6, 8, 9, 12, 16, 19, 20, 22, 23, 24, 26, 27, 28,
  29, 31, 32, 33, 35, 36, 39, 43, 46, 47, 49, 50, 51, 53, 54
}

local KW_slots = {
  10, 11, 13, 14, 15, 17, 18, 37, 38, 40, 41, 42, 44, 45
}

local BS_slots = {
  {21, 25, 30, 34}
}

while true do
  gp.setBackground(colors.black)

  local UH = {}
  for i, slot in ipairs(UH_slots) do
    UH[i] = getDuri(slot)
  end

  local KW = {}
  for i, slot in ipairs(KW_slots) do
    KW[i] = getDuri(slot)
  end

  local BS = {}
  for i, slot in ipairs(BS_slots) do
    BS[i] = getDuri(slot)
  end

  local line = string.rep("-", 51)
  gp.setForeground(colors.orange)
  centerF(2, line)
  centerF(3, "-----               Atomreaktor               -----")
  centerF(4,line)
  gp.setForeground(colors.green)
  -- string.format doesn't do anything here, so simply pass the string
  centerF(6, "Brennstäbe")

  term.setCursor(2, 7)
  -- This time we actually use string.format
  local str = string.format(
    "1: <color fg=%d>%d/color>/%d | 2: <color fg=%d>%d</color>/%d | 3: <color fg=%d>%d</color>/%d",
    -- number in first square brackets is for the selecting the fuel rod
    -- the second numbers: 4 is color, 2 is damage, 3 is max damage
    BS[1][4], BS[1][2], BS[1][3],
    BS[2][4], BS[2][2], BS[2][3],
    BS[3][4], BS[3][2], BS[3][3]
  )
  -- The numbers aren't padded (using makepadding), but you can easily add that
  aw.write(str)

  os.sleep(1)
end

 

Share this post


Link to post
Share on other sites
  • 0

Yeah ok thanks CptMercury i test it later and can you give the original first script, but later because im not at home

Share this post


Link to post
Share on other sites
  • 0

Okay i have test it but it wont work!

2020-07-11_14_36_45.thumb.png.dd31de4bed76438884c0358ddf2af963.png

 

In order to inform you

On 7/9/2020 at 6:25 PM, CptMercury said:

I assume these stand for color (BS1C), damage (BS1D) and max damage (BS1MD), am I correct? But what is the BS1S etc for? From the script it looks like it is the damage swell, but I'm not sure.

The BS1S stands for the space after the "1:" and of course the BS2S for the space after "2:" in the aw.write(.....) thing. And i have send you the original reactor.lua file that ive made at first.

reactor.lua

Share this post


Link to post
Share on other sites
  • 0
22 minutes ago, Leutech said:

Okay i have test it but it wont work!

Yea, I accidentally added a pair of extra curly braces in line 104. Change it to:

local BS_slots = {
  21, 25, 30, 34
}
24 minutes ago, Leutech said:

The BS1S stands for the space after the "1:" and of course the BS2S for the space after "2:" in the aw.write(.....) thing. And i have send you the original reactor.lua file that ive made at first.

Ahh, ok, now I understand. I'll have a look at the file.

Share this post


Link to post
Share on other sites
  • 0

Ok, I missed an opening "<" in line 137 apparently.

Change the string to

  "1: <color fg=%d>%d</color>/%d | 2: <color fg=%d>%d</color>/%d | 3: <color fg=%d>%d</color>/%d"

 

And btw, I saw you were collecting the information about all your components in the reactor but only printing the data of your fuel rods. Do you plan on displaying all the data or just for the fuel rods?

Share this post


Link to post
Share on other sites
  • 0

Yeah i plan to display alle the data and a automatic shutdown for the reactor if his heat to high and the screen should display the current states: "Reactor is running", "Reactor has very high temperature", "WARNING MELTDOWN!"

But i plan to display the other components such like this:

XXOXXXOXX
WWXWWWXWW
XXUXXXUXX
XXUXXXUXX
WWXWWWXWW
XXOXXXOXX

X = Overclocked Heat Vent
W = Component Heat Exchanger
U = Quad Fuel Rod (Uranium)
O = Component Heat Vent

Only in this display the Components: X, W and U should be colored in the state of there damage.

Share this post


Link to post
Share on other sites
  • 0

So i have it now but if i execute the script he says me this error:

2020-07-11_16_42_05.thumb.png.7f4d92d71597e437cdfca62c186624e6.png

 

And the script looks now:

local component = require("component")
local computer  = require("computer")
local term      = require("term")
local aw        = require("adWrite")

local ic        = component.inventory_controller
local gp        = component.proxy(component.get("6fa6e9ed"))
local rc        = component.proxy(component.get("c3f546da"))
local tr        = component.proxy(component.get("7621f0f8"))

local rslamps   = component.proxy(component.get("61d91131"))
local rsreactor = component.proxy(component.get("a0a9b4d3"))

local colors = {
  green  = 0x00FF00,
  yellow = 0xFFFF00,
  orange = 0xFFA800,
  black  = 0x000000,
  white  = 0xFFFFFF,
  red    = 0xFF0000,
  blue   = 0x0000FF,
  cyan   = 0x00FFFF
}

function write(zeile, spalte, str)
  term.setCursor(spalte, zeile)
  aw.write(str)
end

function centerF(row, str)
  w = gp.getResolution()
  term.setCursor((w - #str)/2, row)
  term.write(str)
end

gp.setResolution(85, 27)

term.clear()
term.setCursor(1 ,1)

local dmg_colors = {[0] =
  "0x008421",
  "0x00FF00",
  "0xFFFF00",
  "0xFFA800",
  "0xFF6D00",
  "0xFF3A00",
  "0xFF2B00",
  "0xFF2B00",
  "0xFF0000"
}

local function getDuri(slot)
  local item     = ic.getStackInSlot(3, slot)
  local dmg      = item.damage
  local maxdmg   = item.maxDamage
  local prozent = math.ceil(dmg / maxdmg * 8)

  local dmgColor = dmg_colors[prozent]
  return {item, dmg, maxdmg, dmgColor}
end

local function makepadding(text, max)
  return string.rep(" ", #tostring(text) - max)
end

local UH_slots = {
  1, 2, 4, 5, 6, 8, 9, 12, 16, 19, 20, 22, 23, 24, 26, 27, 28,
  29, 31, 32, 33, 35, 36, 39, 43, 46, 47, 49, 50, 51, 53, 54
}

local KW_slots = {
  10, 11, 13, 14, 15, 17, 18, 37, 38, 40, 41, 42, 44, 45
}

local BS_slots = {
  21, 25, 30, 34
}

while true do
  gp.setBackground(colors.black)

  local UH = {}
  for i, slot in ipairs(UH_slots) do
    UH[i] = getDuri(slot)
  end

  local KW = {}
  for i, slot in ipairs(KW_slots) do
    KW[i] = getDuri(slot)
  end

  local BS = {}
  for i, slot in ipairs(BS_slots) do
    BS[i] = getDuri(slot)
  end

  local line = string.rep("-", 51)
  gp.setForeground(colors.orange)
  centerF(2, line)
  centerF(3, "-----               Atomreaktor               -----")
  centerF(4,line)
  gp.setForeground(colors.green)
  centerF(6, "Brennstäbe")

  term.setCursor(9, 7)
  gp.setForeground(colors.white)
  local str = string.format(
    "1: <color fg=%d>%d</color>/%d | 2: <color fg=%d>%d</color>/%d | 3: <color fg=%d>%d</color>/%d | 4: <color fg=%d>%d</color>/%d",
    BS[1][4], BS[1][2], BS[1][3],
    BS[2][4], BS[2][2], BS[2][3],
    BS[3][4], BS[3][2], BS[3][3],
    BS[4][4], BS[4][2], BS[4][3]
  )
  aw.write(str)
  term.setCursor(2, 8)
  gp.setForeground(colors.cyan)
  centerF(9, "Komponenten")
  gp.setForeground(colors.white)

  local str1 = string.format(
    "<color fg=%d>X</color><color fg=%d>X</color>O<color fg=%d>X</color><color fg=%d>X</color><color fg=%d>X</color>O<color fg=%d>X</color><color fg=%d>X</color>",
    UH[1][4], UH[2][4], UH[3][4], UH[4][4], UH[5][4], UH[6][4], UH[7][4]
  )
  local str2 = string.format(
    "<color fg=%d>W</color><color fg=%d>W</color><color fg=%d>X</color><color fg=%d>W</color><color fg=%d>W</color><color fg=%d>W</color><color fg=%d>X</color><color fg=%d>W</color><color fg=%d>W</color>",
    KW[1][4], KW[2][4], UH[8][4], KW[3][4], KW[4][4], KW[5][4], UH[9][4], KW[6][4], KW[7][4]
  )
  local str3 = string.format(
    "<color fg=%d>X</color><color fg=%d>X</color><color fg=%d>U</color><color fg=%d>X</color><color fg=%d>X</color><color fg=%d>X</color><color fg=%d>U</color><color fg=%d>X</color><color fg=%d>X</color>",
    UH[10][4], UH[11][4], BS[1][4], UH[12][4], UH[13][4], UH[14][4], BS[2][4], UH[15][4], UH[16][4]
  )
  local str4 = string.format(
    "<color fg=%d>X</color><color fg=%d>X</color><color fg=%d>U</color><color fg=%d>X</color><color fg=%d>X</color><color fg=%d>X</color><color fg=%d>U</color><color fg=%d>X</color><color fg=%d>X</color>",
    UH[17][4], UH[18][4], BS[3][4], UH[19][4], UH[20][4], UH[21][4], BS[4][4], UH[22][4], UH[23][4]
  )
  local str5 = string.format(
    "<color fg=%d>W</color><color fg=%d>W</color><color fg=%d>X</color><color fg=%d>W</color><color fg=%d>W</color><color fg=%d>W</color><color fg=%d>X</color><color fg=%d>W</color><color fg=%d>W</color>",
    KW[8][4], KW[9][4], UH[24][4], KW[10][4], KW[11][4], KW[12][4], UH[25][4], KW[13][4], KW[14][4]
  )
  local str6 = string.format(
    "<color fg=%d>X</color><color fg=%d>X</color>O<color fg=%d>X</color><color fg=%d>X</color><color fg=%d>X</color>O<color fg=%d>X</color><color fg=%d>X</color>",
    UH[26][4], UH[27][4], UH[28][4], UH[29][4], UH[30][4], UH[31][4], UH[32][4]
  )
  term.setCursor(38, 10)
  aw.write(str1)
  term.setCursor(38, 11)
  aw.write(str2)
  term.setCursor(38, 12)
  aw.write(str3)
  term.setCursor(38, 13)
  aw.write(str4)
  term.setCursor(38, 14)
  aw.write(str5)
  term.setCursor(38, 15)
  aw.write(str6)
  term.setCursor(1, 16)
  gp.setForeground(colors.yellow)
  centerF(17, "Legende")
  term.setCursor(1, 18)
  gp.setForeground(colors.white)
  term.setCursor(20, 18)
  aw.write("X = Übertakter Hitzeabzug")
  term.setCursor(20, 19)
  aw.write("O = Komponenten-Hitzeabzug")
  term.setCursor(20, 20)
  aw.write("U = Vierfach-Brennstab (Uran)")
  term.setCursor(20, 21)
  aw.write("W = Komponenten-Wärmetauscher")
  
  local rcHeat = rc.getHeat()
  local rcMaxHeat = rc.getMaxHeat()
  local rcProzent = math.ceil(rcHeat / rcMaxHeat * 4)
  local rcStatus = ""

  if rcProzent == 0 then
    rcStatus = "<color fg=0x00FF00>Alles OK </color>"
--    rsreactor.setOutput(3, 20)
  elseif rcProzent == 1 then
    rcStatus = "<color fg=0xFFFF00>Warm</color>"
  elseif rcProzent == 2 then
    rcStatus = "<color fg=0xFFA800>Sehr Warm</color>"
  elseif rcProzent == 3 then
    rcStatus = "<color fg=0xFF3A00>Sehr Heiß</color>"
  elseif rcProzent == 4 then
    rcStatus = "<color fg=0xFF0000>ACHTUNG KERNSCHMELZE STEHT BEVOR!</color>"
--    rsreactor.setOutput(3, 0)
  end
  term.setCursor(30, 23)
  aw.write("Reaktor Status: " ..rcStatus)
  local rcOnline = rc.producesEnergy()
  if rcOnline then
    term.setCursor(1, 24)
    gp.setForeground(colors.green)
    centerF(24, "Online")
  else
    term.setCursor(1, 24)
    gp.setForeground(colors.red)
    centerF(24, "Offline")
  end
  os.sleep(1)
end

 

Share this post


Link to post
Share on other sites
  • 0

That is a really weird bug. I don't really have an idea where exactly this is coming from, especially what function tries to yield. What version of OC are you running? I couldn't find the lines in my machine.lua file that your traceback is showing.

But besides that, using the adwrite function for this is not really appropriate. I have written this function for really basic string coloring, it was not optimized for printing text where every character has a different color.

I'll post a more suitable method for this in a few minutes.

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.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   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...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.