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

Script terminating - no (visible) errors

Started by KingofGamesYami, 23 December 2014 - 11:56 PM
KingofGamesYami #1
Posted 24 December 2014 - 12:56 AM
pastebin: http://pastebin.com/NUuU15WA

For some reason, this will occasionally stop working when hooked up to a monitor. I'm not sure if it's getting terminated for taking too long or what, but if someone spots a likely suspect, please tell me.
Dragon53535 #2
Posted 24 December 2014 - 05:29 AM
My best guess is this bit of code:

for i, circle in pairs( tCircles ) do
					   --Snip--
						if circle.r > ( maxx / 2 ) then
								table.remove( tCircles, i ) --#This
						end
				end
From what i can tell, it probably won't like you removing a circle while you're looking at them all…
Best solution would probably be to do this:

local cDelete = {}
for i, circle in pairs( tCircles ) do
						local t = tWindows[ circle.parent ]
						local maxx, maxy = t.getSize()
						term.redirect( t )
						--[[
						for x = 1, maxx, 0.75 / circle.r do
								local y1, y2 = getY( circle.x, circle.y, circle.r, x )
								t.setCursorPos( x, y1 )
								t.write( " " )
								t.setCursorPos( x, y2 )
								t.write( " " )
						end
						]]--
						drawCircle( circle.x, circle.y, circle.r, colors.blue, false )
						circle.r = circle.r + 1
						if circle.r > ( maxx / 2 ) then
								table.insert( cDelete, i )
						end
				end
for _,del in pairs( cDelete ) do
  tCircles[del] = nil
end

Edit: After actually testing the code with my solution i can safely say, I AM RIGHT! IT WORKS! MWAHAHAHAHHA

Edit2: After testing more, it seems that after a while it throws a java exception… I'll find the cause

Edit3: Testing even more, i cannot reproduce the damn java exception, WHY MUST THIS PROGRAM TOY WITH ME!
Edited on 24 December 2014 - 04:43 AM
Bomb Bloke #3
Posted 24 December 2014 - 05:55 AM
You could also construct the loop without an iterator function:

for i = #tCircles, 1, -1 do
  local circle = tCircles[i]
  etc

This'd remove the need for a separate "cDelete" table, as you'd be able to remove redundant entries while the original loop was still running.

I'm not entirely sure that issue is related to the original problem, though (as confusing pairs by removing table indexes mid-loop should specifically trigger an error). If you're still having problems, describe what "stop working" means - what DOES happen? Do you get dumped out to the prompt, or is the system shutting down, or…?
KingofGamesYami #4
Posted 24 December 2014 - 03:29 PM
What happens is the cursor is set to (1, 1) with out the >. I thought the error was getting eaten by the window api, but then I got an actual error so… I'll try getting rid of the pairs, see if that works.