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

Loop repeats one more time

Started by Zelman89, 14 July 2013 - 12:53 PM
Zelman89 #1
Posted 14 July 2013 - 02:53 PM
Full code if interested. The zDrive contains "for k,v then" type loop functions. Not sure if this is a loop paradox issue or something crazy.

Spoiler–Phase 4 The loop
parallel.waitForAny(
function()
while true do
–Term Writing
if nir == 2 then
zDrive.slotPerTerm(reader1, col1, row1, slotMax1)
zDrive.slotPerTerm(reader2, col2, row1, slotMax2)
elseif nir == 1 then
zDrive.slotPerTerm(reader1, col1, row1, slotMax1)
end
–Mon Writing
if MO == 2 then
if nir == 2 then
zDrive.slotPerMon(reader1, 1, 2, slotMax1, mon1, ckMon1)
zDrive.slotPerMon(reader2, 1, 2, slotMax2, mon2, ckMon2)
elseif nir == 1 then
zDrive.slotPerMon(reader1, 1, 2, slotMax1, mon1, ckMon1)
end
elseif (MO == 1) and (nir >= 1) then
zDrive.slotPerMon(reader1, 1, 2, slotMax1, mon1, ckMon1)
end
sleep(0)
end end,
function()
while true do
event, char = os.pullEvent("char")
if char == "r" then
shell.run("storageL")
elseif char == "h" then
shell.run("storageL")
else
zDrive.monClear(MO, mon1, mon2)
zDrive.monClear(1, term, nil)
term.setCursorPos(1, 1)
break
end
end
end
)

everything works so I put in a spoiler but here is my issue.

  function()
	while true do
	  event, char = os.pullEvent("char")
	  if char == "r" then
		shell.run("storageL")
	  elseif char == "h" then
		shell.run("storageL")
	  else
		zDrive.monClear(MO, mon1, mon2)
		zDrive.monClear(1, term, nil)
		term.setCursorPos(1, 1)
		break
	  end
	end
  end

if I press any key not noted it ends the loop and clears the screen but sometimes it runs the first part one more time. Not sure if the cache is not clearing or what. I want to press any key and the screen clears and it ready for the next input. Any ideas what my issue is.
Zelman89 #2
Posted 14 July 2013 - 02:56 PM
I think I found my issue. Had to add a longer Sleep for the first action to finish so it was trying to break something it couldn't break.