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

Issue with program & occasional crash.

Started by ksbd, 16 January 2013 - 09:59 AM
ksbd #1
Posted 16 January 2013 - 10:59 AM
Firstly, I wasn't sure where to post this, so apologies if it's in the wrong place. I'm not sure if it's just bad coding causing the crash or not, sooo. (Noob here.)

Secondly, I'm using the Direwolf20 pack on the FTB launcher.

What I'm trying to do is use the misc peripherals mod to detect when a redstone energy cell is full via the gate reader block. The code works fine when it is run outside of a loop, but fails to detect any change if a redstone energy cell is to lose energy, become full, etc. On occasion, when the cell was originally 'not full', and I replace it with a full one, and then enter the computer interface to see what's happening, the game will crash. I saved the code as "startup" so it runs right away, but even without this, the same problems occur.

The code:

local m = peripheral.wrap("front")
local data
local dfull
local x = 0
data = m.get()
dfull = data["Full Energy"]
while x == 0 do
  if dfull then
	print("Full!")
	redstone.setOutput("back", true)
	sleep(10)
  else
	print("Not Full!")
	redstone.setOutput("back", false)
	sleep(2)
  end
end

If I should be asking this on a different forum, I am sorry. I'd appreciate it if you could point me in the right direction. But if anyone knows what I'm doing wrong, please tell me what it is.
Also, if it's any help, the output will always read Full! or Not Full! depending on what is true when the code first runs, but this will not change, even if the energy cell's charge does.
immibis #2
Posted 16 January 2013 - 11:01 AM
The first part of the program, before "while true do", is what actually reads the gate.
Because it's outside the loop, you're only reading the gate once, then constantly checking what you read before (which won't change).

Edit: If the game crashes, post a crash report.
ksbd #3
Posted 16 January 2013 - 11:03 AM
Well, that's just embarrassingly simple. Thank you very much.