This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
renjestoo's profile picture

Multiple Points error in Computercraft 1.58

Started by renjestoo, 18 April 2015 - 10:06 PM
renjestoo #1
Posted 19 April 2015 - 12:06 AM
Hello all,

I created my first script here, and it gives me the error "Multiple Points"

Can you guys help me?

Here is the script I wrote:


local monitor = peripheral.wrap("monitor_0")
local mon2 = peripheral.wrap("monitor_1")
local reactor1 = peripheral.wrap("BigReactors-Reactor_0")
local reactor2 = peripheral.wrap("BigReactors-Reactor_1")
cm = peripheral.wrap("tileentitymonitorstoragefluid_1")
local rp1 = reactor1.getEnergyStored()
local rp2 = reactor2.getEnergyStored()
local rt1 = reactor1.getFuelTemperature()
local rt2 = reactor1.getFuelTemperature()
local rpt = textutils.serialize(rp1+rp2)
local rtt = textutils.serialize(rt1+rt2)
local backup = peripheral.wrap("up")
local mainpower = peripheral.wrap("back")
local totalbytes = cm.getTotalBytes()
local usedbytes = cm.getFreeBytes()
local unusedbytes = cm.getUnusedBytes()

local function getPower(i)
  local p = peripheral.wrap("bottom")
  return p.callRemote(i, "getEnergyStored", "none")
end

local function getPeripherals()
  local t = {}
  for k,v in pairs(peripheral.getNames()) do
    if (string.find(v,"cofh_thermalexpansion_energycell")) then
	  t[v] = getPower(v)
    end
  end
  return t
end

function mesystem()
  monitor.clear()
  monitor.setTextScale(0.5)
  monitor.setCursorPos(1,1)
  monitor.write("==============================")
  monitor.setCursorPos(1,2)
  monitor.write("Totale Opslag Terminal:")
  monitor.setCursorPos(1,3)
  if totalbytes >= 0 and totalbytes < 1000 then 
    monitor.write(textutils.unserialize(totalbytes.." Bytes"))
  elseif totalbytes >= 1000 and totalbytes <= 999999 then
    monitor.write(textutils.unserialize(totalbytes/1000.." KiloByte"))
  elseif totalbytes >= 1000000 and totalbytes <= 999999999 then
    monitor.write(textutils.unserialize(totalbytes(/1000000).."MegaBytes"))
  end
  monitor.setCursorPos(1,5)
  monitor.write("Gebruikte ruimte in de Terminal:")
  monitor.setCursorPos(1,6)
  monitor.write(textutils.unserialize(usedbytes.." Bytes"))
  monitor.setCursorPos(1,8)
  monitor.write("Ongebruikte ruimte in de Terminal:")
  monitor.setCursorPos(1,9)
  monitor.write(textutils.unserialize(unusedbytes.." Bytes"))
  monitor.setCursorPos(1,10)
  monitor.write("==============================")
end

function reactor()
  local t = getPeripherals()
  local power = 0
  local i = 0
  mon2.clear()
  mon2.setTextScale(0.5)
  mon2.setCursorPos(1,1)
  for k,v in pairs(t) do
    power = power + v
    i = i + 1
  end
  mon2.write("===============================")
  mon2.setCursorPos(1,3)
  mon2.write("Reactor 1 Power = "..reactor1.getEnergyStored())
  mon2.setCursorPos(1,4)
  mon2.write("Reactor 1 Temp = "..reactor1.getFuelTemperature())
  mon2.setCursorPos(1,6)
  mon2.write("Reactor 2 Power = "..reactor2.getEnergyStored())
  mon2.setCursorPos(1,7)
  mon2.write("Reactor 2 Temp = "..reactor2.getFuelTemperature())
  mon2.setCursorPos(1,9)
  mon2.write("===============================")
  mon2.setCursorPos(1,12)
  mon2.write("Gemiddelde Backup Power: "..(power/i))
  if power/i >= 9000000 then
    redstone.setOutput("back", true)
    mon2.setCursorPos(1,11)
    mon2.write("Backup Power Ingeschakeld!")
  elseif power/i <= 1000000 then
    redstone.setOutput("back", false)
    mon2.setCursorPos(1,11)
    mon2.write("Backup Power aan het opladen!")
  end
end

function loop()
  while true do
    reactor()
    sleep(0.5)
    mesystem()
    sleep(0.5)
  end
end

loop()
I hope you can help me out with this

Kind regards,
Renjestoo
HPWebcamAble #2
Posted 19 April 2015 - 12:24 AM
That means you tried to create a number with more than one decimal. Yah, its a terrible description, I think its better in CC 1.7

Pretty sure its this line:

--# A few lines into your 'mesystem' function

monitor.write(textutils.unserialize(totalbytes/1000.." KiloByte"))

Its complaining because of '1000..'

Just do this:

monitor.write(textutils.unserialize(totalbytes/ tostring( 1000 ) .." KiloByte"))
Edited on 18 April 2015 - 10:25 PM
Creator #3
Posted 19 April 2015 - 12:32 AM
Or rather this:

monitor.write(textutils.unserialize(tostring(totalbytes/1000)  .." KiloByte"))
Since you can't divide strings, as was suggestion your suggestion. Suggesception…
renjestoo #4
Posted 19 April 2015 - 01:04 AM
thanks, this solved my issue completely :D/>

I indeed forgot to set it to "tostring" :S

Again thanks ;)/>
valithor #5
Posted 19 April 2015 - 01:29 AM
Actually both of those suggestions involve doing more than is actually needed you could alternatively just do this.


monitor.write(textutils.unserialize((totalbytes/1000).." KiloByte"))

Notice there is no need for the tostring, which makes it more efficient. Instead just wrapping the number in parenthesis will cause it to not think you are trying to create a number with multiple decimal points.

edit:

technically lua automatically tostrings the number when concatinating, so this is more if you are just lazy like me and dont feel like writing out tostring :P/>/>.
Edited on 18 April 2015 - 11:33 PM
Lignum #6
Posted 19 April 2015 - 01:33 AM
Not quite related, but 1 byte = 1024 KB.
Edited on 18 April 2015 - 11:38 PM
valithor #7
Posted 19 April 2015 - 01:35 AM
Not quite related, but 1 byte = 1024 KB.

Actually 1 KB is 1024 byte.

http://www.whatsabyte.com
Lignum #8
Posted 19 April 2015 - 01:38 AM
Not quite related, but 1 byte = 1024 KB.

Actually 1 KB is 1024 byte.

http://www.whatsabyte.com

Ah yes, you're right. Got them mixed up.. it's really late here.
HPWebcamAble #9
Posted 19 April 2015 - 04:35 AM
Notice there is no need for the tostring, which makes it more efficient

Its a game :P/>


you can't divide strings

In most languages, no, but in Lua, you can

"1" + "1" --#> 2 (Number)

"8" / "2" --#> 4 (Number)
Creator #10
Posted 19 April 2015 - 08:08 AM
Interesting this is.
renjestoo #11
Posted 20 April 2015 - 02:47 AM
Hey there,

I was wondering why my scripts isn't working correctly.

1st = It takes for about 10 seconds to complete 1 loop
2nd = the colors don't change based on the data it gets
3rd = it doesn't show the text I ask him to show

this threat is mainly based on the "mon2" part of the script with the function(s) backup(), charge() and loop().

Can somebody help me with this?

I am not a complete idiot, but I am also not a experienced Lua scripter. So if I did something wrong, please tell me :D/>

Here is my complete script:


local monitor = peripheral.wrap("monitor_0")
local mon2 = peripheral.wrap("monitor_1")
local reactor1 = peripheral.wrap("BigReactors-Reactor_0")
local reactor2 = peripheral.wrap("BigReactors-Reactor_1")
cm = peripheral.wrap("appeng_me_tilecontroller_0")
local rp1 = reactor1.getEnergyStored()
local rp2 = reactor2.getEnergyStored()
local rt1 = reactor1.getFuelTemperature()
local rt2 = reactor1.getFuelTemperature()
local rpt = textutils.serialize(rp1+rp2)
local rtt = textutils.serialize(rt1+rt2)
local backup = peripheral.wrap("up")
local mainpower = peripheral.wrap("back")
local totalbytes = cm.getTotalBytes()
local usedbytes = cm.getFreeBytes()
local unusedbytes = cm.getUnusedBytes()
local green = mon2.setTextColor(colors.green)
local red = mon2.setTextColor(colors.red)

local function getPower(i)
  local p = peripheral.wrap("bottom")
  return p.callRemote(i, "getEnergyStored", "none")
end

local function getPeripherals()
  local t = {}
  for k,v in pairs(peripheral.getNames()) do
    if (string.find(v,"cofh_thermalexpansion_energycell")) then
	  t[v] = getPower(v)
    end
  end
  return t
end

function mesystem()
  monitor.clear()
  monitor.setTextScale(0.5)
  monitor.setCursorPos(1,1)
  monitor.write("==============================")
  monitor.setCursorPos(1,2)
  monitor.write("Totale Opslag Terminal:")
  monitor.setCursorPos(1,3)
  if totalbytes >= 0 and totalbytes < 1000 then 
    monitor.write(textutils.unserialize(totalbytes.." Bytes"))
  elseif totalbytes >= 1000 and totalbytes < 1000000 then
    monitor.write(textutils.unserialize(tostring(totalbytes/1000).." KiloByte"))
  elseif totalbytes >= 1000000 and totalbytes < 1000000000 then
    monitor.write(textutils.unserialize(tostring(totalbytes/1000000).." MegaBytes"))
  end
  monitor.setCursorPos(1,5)
  monitor.write("Ongebruikte ruimte in de Terminal:")
  monitor.setCursorPos(1,6)
  if usedbytes >= 0 and usedbytes < 1000 then
    monitor.write(textutils.unserialize(usedbytes.." Bytes"))
  elseif usedbytes >= 1000 and usedbytes < 1000000 then
    monitor.write(textutils.unserialize(tostring(usedbytes/1000).." KiloBytes"))
  elseif usedbytes >= 1000000 and usedbytes < 1000000000 then
    monitor.write(textutils.unserialize(tostring(usedbytes/1000000).." MegaBytes"))
  end
  monitor.setCursorPos(1,8)
  monitor.write("Gebruikte ruimte in de Terminal:")
  monitor.setCursorPos(1,9)
  if unusedbytes >= 0 and unusedbytes < 1000 then
    monitor.write(textutils.unserialize(unusedbytes.." Bytes"))
  elseif unusedbytes >= 1000 and unusedbytes < 1000000 then
    monitor.write(textutils.unserialize(tostring(unusedbytes/1000).." KiloBytes"))
  elseif unusedbytes >= 1000000 and unusedbytes < 1000000000 then
    monitor.write(textutils.unserialize(tostring(unusedbytes/1000000).." MegaBytes"))
  end
  monitor.setCursorPos(1,10)
  monitor.write("==============================")
end

function reactor()
  local t = getPeripherals()
  local power = 0
  local i = 0
  mon2.clear()
  mon2.setTextScale(0.5)
  mon2.setCursorPos(1,1)
  for k,v in pairs(t) do
    power = power + v
    i = i + 1
  end
  mon2.write("===============================")
  mon2.setCursorPos(1,3)
  mon2.write("Reactor 1 Power = "..reactor1.getEnergyStored())
  mon2.setCursorPos(1,4)
  mon2.write("Reactor 1 Temp  = "..reactor1.getFuelTemperature())
  mon2.setCursorPos(1,6)
  mon2.write("Reactor 2 Power = "..reactor2.getEnergyStored())
  mon2.setCursorPos(1,7)
  mon2.write("Reactor 2 Temp  = "..reactor2.getFuelTemperature())
  mon2.setCursorPos(1,9)
  mon2.write("===============================")
  mon2.setCursorPos(1,12)
  mon2.write("Gemiddelde Backup Power: "..(power/i))
end

local function backup()
  local t = getPeripherals()
  local power = 0
  local i = 0
  mon2.setTextScale(0.5)
  mon2.setCursorPos(1,1)
  for k,v in pairs(t) do
    power = power + v
    i = i + 1
  end
  if power/i >= 9000000 then
    redstone.setOutput("back", true)
    sleep(0)
    mon2.setCursorPos(1,11)
    mon2.write("Backup power ingeschakeld!")
  end
end

local function charge()
  local t = getPeripherals()
  local power = 0
  local i = 0
  mon2.setTextScale(0.5)
  mon2.setCursorPos(1,1)
  for k,v in pairs(t) do
    power = power + v
    i = i + 1
  end
  if power/i <= 1000000 then
    redstone.setOutput("back", false)
    sleep(0)
    mon2.setCursorPos(1,11)
    mon2.write("Backup Power aan het opladen!")
  end
end

function loop()
  while true do
    reactor()
    sleep(0.1)
    mesystem()
    backup()
    charge()
    if backup() then
	    mon2.setTextColor(colors.red)
    elseif charge() then
	    mon2.setTextColor(colors.green)
    end
  end
end

loop()

if you know what is wrong with my script, then please tell me, or even correct it in its complete state.

Kind regards,
Renjestoo
renjestoo #12
Posted 20 April 2015 - 02:51 AM
Not quite related, but 1 byte = 1024 KB.

Actually 1 KB is 1024 byte.

http://www.whatsabyte.com

Ah yes, you're right. Got them mixed up.. it's really late here.

Damn naggit, I really screwed up there :P/>. I'll have to change that :D/>
so it has to devide by 1024
but then??? do I have to devide it by 1024000 ??? I don't know :P/>
renjestoo #13
Posted 20 April 2015 - 03:42 AM
Hey there,

I was wondering why my script isn't working exactly as I would like it to work.

The problem is, that when a powerlevel from Redstone Energy cells gets to a specific point, the color and text doesn't change/show
Also the loop in the script takes for about 5 - 10 seconds (I don't know why)

Announcement: I am not a professional Lua scripter nor have I ever learned for Lua. Just looked a lot at youtube clips and tutorials like this.
BTW… no, I am not a nitwit and I am working for Microsoft, so please hit me when there is obviously something wrong ;)/>. I only never did Scripting :D/>

this is the script:



local monitor = peripheral.wrap("monitor_0")
local mon2 = peripheral.wrap("monitor_1")
local reactor1 = peripheral.wrap("BigReactors-Reactor_0")
local reactor2 = peripheral.wrap("BigReactors-Reactor_1")
cm = peripheral.wrap("appeng_me_tilecontroller_0")
local rp1 = reactor1.getEnergyStored()
local rp2 = reactor2.getEnergyStored()
local rt1 = reactor1.getFuelTemperature()
local rt2 = reactor1.getFuelTemperature()
local rpt = textutils.serialize(rp1+rp2)
local rtt = textutils.serialize(rt1+rt2)
local backup = peripheral.wrap("up")
local mainpower = peripheral.wrap("back")
local totalbytes = cm.getTotalBytes()
local usedbytes = cm.getFreeBytes()
local unusedbytes = cm.getUnusedBytes()
local green = mon2.setTextColor(colors.green)
local red = mon2.setTextColor(colors.red)

local function getPower(i)
  local p = peripheral.wrap("bottom")
  return p.callRemote(i, "getEnergyStored", "none")
end

local function getPeripherals()
  local t = {}
  for k,v in pairs(peripheral.getNames()) do
    if (string.find(v,"cofh_thermalexpansion_energycell")) then
	  t[v] = getPower(v)
    end
  end
  return t
end

function mesystem()
  monitor.clear()
  monitor.setTextScale(0.5)
  monitor.setCursorPos(1,1)
  monitor.write("==============================")
  monitor.setCursorPos(1,2)
  monitor.write("Totale Opslag Terminal:")
  monitor.setCursorPos(1,3)
  if totalbytes >= 0 and totalbytes < 1000 then
    monitor.write(textutils.unserialize(totalbytes.." Bytes"))
  elseif totalbytes >= 1000 and totalbytes < 1000000 then
    monitor.write(textutils.unserialize(tostring(totalbytes/1024).." KiloByte"))
  elseif totalbytes >= 1000000 and totalbytes < 1000000000 then
    monitor.write(textutils.unserialize(tostring(totalbytes/1048576).." MegaBytes"))
  end
  monitor.setCursorPos(1,5)
  monitor.write("Ongebruikte ruimte in de Terminal:")
  monitor.setCursorPos(1,6)
  if usedbytes >= 0 and usedbytes < 1000 then
    monitor.write(textutils.unserialize(usedbytes.." Bytes"))
  elseif usedbytes >= 1000 and usedbytes < 1000000 then
    monitor.write(textutils.unserialize(tostring(usedbytes/1024).." KiloBytes"))
  elseif usedbytes >= 1000000 and usedbytes < 1000000000 then
    monitor.write(textutils.unserialize(tostring(usedbytes/1048576).." MegaBytes"))
  end
  monitor.setCursorPos(1,8)
  monitor.write("Gebruikte ruimte in de Terminal:")
  monitor.setCursorPos(1,9)
  if unusedbytes >= 0 and unusedbytes < 1000 then
    monitor.write(textutils.unserialize(unusedbytes.." Bytes"))
  elseif unusedbytes >= 1000 and unusedbytes < 1000000 then
    monitor.write(textutils.unserialize(tostring(unusedbytes/1024).." KiloBytes"))
  elseif unusedbytes >= 1000000 and unusedbytes < 1000000000 then
    monitor.write(textutils.unserialize(tostring(unusedbytes/1048576).." MegaBytes"))
  end
  monitor.setCursorPos(1,10)
  monitor.write("==============================")
end

function reactor()
  local t = getPeripherals()
  local power = 0
  local i = 0
  mon2.clear()
  mon2.setTextScale(0.5)
  mon2.setCursorPos(1,1)
  for k,v in pairs(t) do
    power = power + v
    i = i + 1
  end
  mon2.write("===============================")
  mon2.setCursorPos(1,3)
  mon2.write("Reactor 1 Power = "..reactor1.getEnergyStored())
  mon2.setCursorPos(1,4)
  mon2.write("Reactor 1 Temp  = "..reactor1.getFuelTemperature())
  mon2.setCursorPos(1,6)
  mon2.write("Reactor 2 Power = "..reactor2.getEnergyStored())
  mon2.setCursorPos(1,7)
  mon2.write("Reactor 2 Temp  = "..reactor2.getFuelTemperature())
  mon2.setCursorPos(1,9)
  mon2.write("===============================")
  mon2.setCursorPos(1,12)
  mon2.write("Gemiddelde Backup Power: "..(power/i))
end

local function backup()
  local t = getPeripherals()
  local power = 0
  local i = 0
  mon2.setTextScale(0.5)
  mon2.setCursorPos(1,1)
  for k,v in pairs(t) do
    power = power + v
    i = i + 1
  end
  if power/i >= 9000000 then
    redstone.setOutput("back", true)
    sleep(0)
    mon2.setCursorPos(1,11)
    mon2.write("Backup power ingeschakeld!")
  end
end

local function charge()
  local t = getPeripherals()
  local power = 0
  local i = 0
  mon2.setTextScale(0.5)
  mon2.setCursorPos(1,1)
  for k,v in pairs(t) do
    power = power + v
    i = i + 1
  end
  if power/i <= 1000000 then
    redstone.setOutput("back", false)
    sleep(0)
    mon2.setCursorPos(1,11)
    mon2.write("Backup Power aan het opladen!")
  end
end


function loop()
  while true do
    reactor()
    sleep(0.1)
    mesystem()
    backup()
    charge()
    if backup() then
	  mon2.setTextColor(colors.red)
    elseif charge() then
	  mon2.setTextColor(colors.green)
    end
  end
end

loop()




Kind regards,
Renjestoo
Lyqyd #14
Posted 20 April 2015 - 06:00 AM
Threads merged.
Bomb Bloke #15
Posted 20 April 2015 - 08:10 AM
Damn naggit, I really screwed up there :P/> . I'll have to change that :D/>
so it has to devide by 1024
but then??? do I have to devide it by 1024000 ??? I don't know :P/>

Your average kilobyte is two to the power of ten (2^10) bytes, or 1,024; a megabyte is 2^20, or 1,048,576; gigs are 2^30, and so on.

The problem is, that when a powerlevel from Redstone Energy cells gets to a specific point, the color and text doesn't change/show

Well, down in the loop at the bottom we have:

    backup()                               -- Run "backup".
    charge()                               -- Run "charge".
    if backup() then                       -- Run "backup" *again*, and if that function returns something that isn't false/nil, then...
	  mon2.setTextColor(colors.red)    -- Change the colour.
    elseif charge() then                   -- Otherwise, run "charge" *again*, and if that function returns something that isn't false/nil, then...
	  mon2.setTextColor(colors.green)  -- Change the colour.
    end

Neither your "charge" nor "backup" functions ever return *anything*, so neither of these conditions will ever be true. Check out the "Function return values" section in this tutorial.
renjestoo #16
Posted 20 April 2015 - 03:44 PM
Damn naggit, I really screwed up there :P/> . I'll have to change that :D/>
so it has to devide by 1024
but then??? do I have to devide it by 1024000 ??? I don't know :P/>

Your average kilobyte is two to the power of ten (2^10) bytes, or 1,024; a megabyte is 2^20, or 1,048,576; gigs are 2^30, and so on.

The problem is, that when a powerlevel from Redstone Energy cells gets to a specific point, the color and text doesn't change/show

Well, down in the loop at the bottom we have:

	
    backup()							   -- Run "backup".
	charge()							   -- Run "charge".
	if backup() then					   -- Run "backup" *again*, and if that function returns something that isn't false/nil, then...
	  mon2.setTextColor(colors.red)	-- Change the colour.
	elseif charge() then				   -- Otherwise, run "charge" *again*, and if that function returns something that isn't false/nil, then...
	  mon2.setTextColor(colors.green)  -- Change the colour.
	end

Neither your "charge" nor "backup" functions ever return *anything*, so neither of these conditions will ever be true. Check out the "Function return values" section in this tutorial.

I tried to understand this. but the "Function return values" is to complicated for me. Can you help me with it?
For now I changed the script. but it still doesn't work correctly :S
the screens now refresh every 2 - 3 seconds and after the refresh the screens are black for about 1 second

also the text I want to get at "mon2" doesn't stay as it is attended :(/>

Sorry for the long posts and long scripts, but I really want this to work :)/>
this is my new script:


local monitor = peripheral.wrap("monitor_0")
local mon2 = peripheral.wrap("monitor_1")
local reactor1 = peripheral.wrap("BigReactors-Reactor_0")
local reactor2 = peripheral.wrap("BigReactors-Reactor_1")
cm = peripheral.wrap("appeng_me_tilecontroller_0")
local rp1 = reactor1.getEnergyStored()
local rp2 = reactor2.getEnergyStored()
local rt1 = reactor1.getFuelTemperature()
local rt2 = reactor1.getFuelTemperature()
local rpt = textutils.serialize(rp1+rp2)
local rtt = textutils.serialize(rt1+rt2)
local backup = peripheral.wrap("up")
local mainpower = peripheral.wrap("back")
local totalbytes = cm.getTotalBytes()
local usedbytes = cm.getFreeBytes()
local unusedbytes = cm.getUnusedBytes()
local function monClear()
monitor.clear()
mon2.clear()
end
local function textScale()
monitor.setTextScale(0.5)
mon2.setTextScale(0.5)
end
local function setRed()
mon2.setTextColor(colors.red)
end
local function setGreen()
mon2.setTextColor(colors.green)
end
local function getPower(i)
local p = peripheral.wrap("bottom")
return p.callRemote(i, "getEnergyStored", "none")
end
local function getPeripherals()
local t = {}
for k,v in pairs(peripheral.getNames()) do
  if (string.find(v,"cofh_thermalexpansion_energycell")) then
   t[v] = getPower(v)
  end
end
return t
end
function mesystem()
monitor.setCursorPos(1,1)
monitor.write("==============================")
monitor.setCursorPos(1,2)
monitor.write("Totale Opslag Terminal:")
monitor.setCursorPos(1,3)
if totalbytes >= 0 and totalbytes < 1000 then 
  monitor.write(textutils.unserialize(totalbytes.." Bytes"))
elseif totalbytes >= 1000 and totalbytes < 1000000 then
  monitor.write(textutils.unserialize(tostring(totalbytes/1000).." KiloByte"))
elseif totalbytes >= 1000000 and totalbytes < 1000000000 then
  monitor.write(textutils.unserialize(tostring(totalbytes/1000000).." MegaBytes"))
end
monitor.setCursorPos(1,5)
monitor.write("Ongebruikte ruimte in de Terminal:")
monitor.setCursorPos(1,6)
if usedbytes >= 0 and usedbytes < 1000 then
  monitor.write(textutils.unserialize(usedbytes.." Bytes"))
elseif usedbytes >= 1000 and usedbytes < 1000000 then
  monitor.write(textutils.unserialize(tostring(usedbytes/1000).." KiloBytes"))
elseif usedbytes >= 1000000 and usedbytes < 1000000000 then
  monitor.write(textutils.unserialize(tostring(usedbytes/1000000).." MegaBytes"))
end
monitor.setCursorPos(1,8)
monitor.write("Gebruikte ruimte in de Terminal:")
monitor.setCursorPos(1,9)
if unusedbytes >= 0 and unusedbytes < 1000 then
  monitor.write(textutils.unserialize(unusedbytes.." Bytes"))
elseif unusedbytes >= 1000 and unusedbytes < 1000000 then
  monitor.write(textutils.unserialize(tostring(unusedbytes/1000).." KiloBytes"))
elseif unusedbytes >= 1000000 and unusedbytes < 1000000000 then
  monitor.write(textutils.unserialize(tostring(unusedbytes/1000000).." MegaBytes"))
end
monitor.setCursorPos(1,10)
monitor.write("==============================")
end
function reactor()
local t = getPeripherals()
local power = 0
local i = 0
for k,v in pairs(t) do
  power = power + v
  i = i + 1
end
mon2.setCursorPos(1,1)
mon2.write("===============================")
mon2.setCursorPos(1,3)
mon2.write("Reactor 1 Power = "..reactor1.getEnergyStored())
mon2.setCursorPos(1,4)
mon2.write("Reactor 1 Temp  = "..reactor1.getFuelTemperature())
mon2.setCursorPos(1,6)
mon2.write("Reactor 2 Power = "..reactor2.getEnergyStored())
mon2.setCursorPos(1,7)
mon2.write("Reactor 2 Temp  = "..reactor2.getFuelTemperature())
mon2.setCursorPos(1,9)
mon2.write("===============================")
mon2.setCursorPos(1,12)
mon2.write("Gemiddelde Backup Power: "..(power/i))
end
function backup()
local t = getPeripherals()
local power = 0
local i = 0
for k,v in pairs(t) do
  power = power + v
  i = i + 1
end
if power/i >= 9000000 then
  redstone.setOutput("back", true)
  mon2.setCursorPos(1,11)
  mon2.write("Backup power ingeschakeld!")
  setRed()
end
end
function charge()
local t = getPeripherals()
local power = 0
local i = 0
for k,v in pairs(t) do
  power = power + v
  i = i + 1
end
if power/i <= 1000000 then
  redstone.setOutput("back", false)
  mon2.setCursorPos(1,11)
  mon2.write("Backup Power aan het opladen!")
  setGreen()
end
end
function loop()
while true do
  monClear()
  textScale()
  reactor()
  mesystem()
  backup()
  charge()
end
end

loop()
KingofGamesYami #17
Posted 20 April 2015 - 04:04 PM
To avoid the 'blank screen' effect, you will want to clear the screen immediately before writing to it. If this doesn't fix it, gather data before clearing, then write it to the screen. This removes the 'lag' of gathering data. (well, not really, but it means the screen isn't blank while it gathers the data)
renjestoo #18
Posted 20 April 2015 - 06:04 PM
still doesn't work :S
Bomb Bloke #19
Posted 21 April 2015 - 12:27 AM
That's a bit better. But you're still doing this:

Clear screens
Query all peripherals for power levels (in the reactor function)
Draw stuff in the reactor function
Draw stuff in the mesystem function
Query all peripherals for power levels (... again, in the backup function)
Draw stuff in the backup function
Query all peripherals for power levels (... yet again, in the charge function)
Draw stuff in the charge function

If you want to get rid of your flicker and speed up your script, you'd want to re-arrange things like so:

Query all peripherals for power levels
Clear screens
Draw stuff in the reactor function
Draw stuff in the mesystem function
Draw stuff in the backup function
Draw stuff in the charge function

getPeripherals() is a slow function, so you don't want to call it more than you have to, and you especially don't want to call it in between clearing your screen and when you redraw. You could make it a little more efficient, though:

local function getPeripherals()
  local cells, power = {peripheral.find("cofh_thermalexpansion_energycell")}, 0
  for i = 1, #cells do power = power + cells[i].getEnergyStored("none") end
  return power
end

Calling reactor1.getEnergyStored(), reactor1.getFuelTemperature(), etc is also slow. Aim to do it before you clear the screen - save the results to variables while the last screen is still visible, do the wipe, then draw the results.