Jump to content




Monitors font work

computer peripheral networking

12 replies to this topic

#1 Dsemagames

  • Members
  • 8 posts

Posted 17 July 2015 - 08:01 AM

I have a program to control a Big Reactor, if i active the function to show information in a advanced monitor, the computer reboot, but if i desactive, the program works. I wrote another program to see if the monitors work and they show text

This is the code :


print("running...")

cap = peripheral.find("tile_blockcapacitorbank_name")
mon = peripheral.wrap("right")
--mon = peripheral.find("monitor")
rea = peripheral.find("BigReactors-Reactor")

local numCapacitors = 2
local enciendeA = 50
local apagaA = 95

local energia = 0
local energiaGuardada = 0
local energiaMax = 0
local energiaGuardadaPorCiento = 0
local produccionRF = 0
local usoFuel = 0
local tempCore = 0
local reactorOnline = false

function enciende()
rea.setActive(true)
end

function apaga()
rea.setActive(false)
end

function comma_value(cantidad)
local formateo = cantidad
local swap = false
if formateo < 0 then
formateo = formateo*-1
swap = true
end
while true do
formateo, k = string.gsub(formateo, "^(%d+)(%d%d%d)",'%1%2')
if k == 0 then
break
end
end
if swap then
formateo = "-"..formateo
end
return formateo
end

function muestraEnergia()
mon.clear()
mon.setCursorPos(1,1)
mon.write("Usa de Energia: ")
if energia < 0 then
mon.setTextColor(colors.red)
else
mon.setTextColor(colors.lime)
end
mon.write(comma_value(math.floor(energia)).."RF/T")
mon.setTextColor(colors.white)
mon.setCursorPos(1,2)
mon.write("Energia Almacenada: ")
if energiaGuardadaPorCiento < 55 then
mon.setTextColor(colors.red)
elseif energiaGuardadaPorCiento >= 55 and energiaGuardadaPorCierto <=85 then
mon.setTextColor(colors.yellow)
else
mon.setTextColor(colors.lime)
end
mon.write(energiaGuardadaPorCiento.."%")
mon.setTextColor(colors.white)
mon.setCursorPos(1,3)
mon.write("Este Reactor esta: ")
if reactorOnline then
mon.setTextColor(colors.lime)
mon.write("ENCENDIDO")
else
mon.setTextColor(colors.red)
mon.write("APAGADO")
end
mon.setTextColor(colors.white)
mon.setCursorPos(1,4)
mon.write("Generacion de RedstoneFluix: ")
mon.setTextColor(colors.lime)
mon.weite(comma_value(math.floor(produccionRF)).."RF/T")
mon.setTextColor(colors.white)
mon.serCursorPos(1,5)
mon.write("Temperatura interna: "..math.floor(tempCore).."c")
mon.setCursorPos(1,6)
mon.write("Uso de Combustible: "..usoFuel.."MB/T")
end

function compruebaEnergia()
local energiaTemporal = 0
energiaGuardada = cap.getEnergyStored()
energiaMax = cap.getMaxEnergyStored()
energiaGuardadaPorCiento = math.floor((energiaGuardada/energiaMax)*100)
produccionRF = rea.getEnergyProducedLastTick()
usoFuel = rea.getFuelConsumedLastTick()
usoFuel = math.floor(usoFuel*100)
usoFuel = usoFuel/100
tempCore = rea.getFuelTemperature()
reactorOnline = rea.getActive()
energiaTemporal = cap.getEnergyStored()
sleep(0.1)
energia = (cap.getEnergyStored()-energiaTemporal)/2
energia = energia*numCapacitors
end

function autoReactor()
rea.setAllControlRodLevels(0)
if energiaGuardadaPorCiento < enciendeA then
if not reactorOnline then
enciende()
end
end
if energiaGuardadaPorCiento > apagaA then
apaga()
end
end

function muestraInfo()
compruebaEnergia()
muestraEnergia()
autoReactor()
end

while true do
muestraInfo()
end



#2 flaghacker

  • Members
  • 655 posts

Posted 17 July 2015 - 11:23 AM

I don't understand your code at all because it isn't english, but I think the problem is that you don't yield.

Yielding is the act of waiting for something (user input, time delay, ...). Your code is forced to yield because commputercraft has to run others computers while you're waiting. Computers don't run in parallell, they simply pretend to do so.

When your program doesn't yield, computercraft shuts it down by erroring "too long without yielding" to allow other computers to keep running.

When your code only executes peripheral functions, computercraft can't error out because it has no control over those functions. The code appears to be running just fine, but it prevents other conputers in the world to do anything.

Conputercraft has control over the monitor functions, so as soon as you start using them your program/computer shuts down. Using the monitor functions isn't the cause of the problem, it simply reveals it.

The solution would be to yield in your main loop, you can eg put a sleep (5) in there.

Edited by flaghacker, 17 July 2015 - 11:24 AM.


#3 Dsemagames

  • Members
  • 8 posts

Posted 17 July 2015 - 04:26 PM

Thanks :D, but now i have other problem in the same code

Error: 63: attempt to compare __le on nil and number

#4 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 17 July 2015 - 05:45 PM

Here is line 63:
elseif energiaGuardadaPorCiento >= 55 and energiaGuardadaPorCierto <=85 then

attempt to compare __le on nil and number means you tried to say 'is nil less than or equal to a number?' (le is less then or equal to)

The second variable, 'energiaGuardadoPorCierto', isn't used anywhere else in the program, so it will always be nil.

#5 Dsemagames

  • Members
  • 8 posts

Posted 27 July 2015 - 06:03 AM

I solve all the errors but the program dont work and now i have a sleep (5) in the main loop

#6 flaghacker

  • Members
  • 655 posts

Posted 27 July 2015 - 08:19 AM

View PostDsemagames, on 27 July 2015 - 06:03 AM, said:

I solve all the errors but the program dont work and now i have a sleep (5) in the main loop

Specify "don't work". What does it do instead? Error? Blank screen?

#7 Dsemagames

  • Members
  • 8 posts

Posted 27 July 2015 - 09:08 AM

The computer shut down

#8 flaghacker

  • Members
  • 655 posts

Posted 27 July 2015 - 09:26 AM

Could you upload your current code to pastebin?

#9 Dsemagames

  • Members
  • 8 posts

Posted 27 July 2015 - 09:33 AM

http://pastebin.com/kgcsNKx9

#10 flaghacker

  • Members
  • 655 posts

Posted 27 July 2015 - 09:42 AM

And when does it shut down, does it print anything first?

#11 Dsemagames

  • Members
  • 8 posts

Posted 27 July 2015 - 10:29 AM

Now works! I change the program to a new computer, and its working. I thing is a bug. Thank for your help ;D

#12 flaghacker

  • Members
  • 655 posts

Posted 27 July 2015 - 11:21 AM

View PostDsemagames, on 27 July 2015 - 10:29 AM, said:

Now works! I change the program to a new computer, and its working. I thing is a bug. Thank for your help ;D

You can try to reboot the 'broken' computer, maybe that fixes it.

#13 Dsemagames

  • Members
  • 8 posts

Posted 27 July 2015 - 11:37 AM

The new computer have the same problem ;(





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users