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

Help with game (QuickDraw)

Started by LDDestroier, 11 April 2016 - 04:59 PM
LDDestroier #1
Posted 11 April 2016 - 06:59 PM
For some odd reason, when running my game, it seems to overwrite some of the sprite tables. But I cannot find any point in the code that would do that. For example, when I start the program with an error() directly after declaring the sprites (which are in a paintutils.loadImage() format), and use the lua interpreter to display it with paintutils.drawImage(), it displays what I want (just the guy, no background). But if I run the game then display the sprites in the lua interpreter, it displays both the guy AND the background.

…help?

I think fixing this problem should fix the inability to miss as well.

Code: uGTzMxNL
moTechPlz #2
Posted 11 April 2016 - 09:10 PM
Hi, it is your 'mixImages' function. With 'output = img1' you copy the pointer of the table not the data itself. So if you then change the data with this pointer you change the data of the original table.

try this code;

function mixImages( img1, img2 )
  local output = { }
  for a = 1, #img2 do
	output[ a ] = { }
	if not img1[ a ] then
	  for b = 1, #img2[ a ] do
		output[ a ][ b ] = img2[ a ][ b ]
	  end
	else
	  for b = 1, #img2[ a ] do
		if img1[ a ][ b ] then
		  if img1[ a ][ b ] ~= 0 then
			output[ a ][ b ] = img1[ a ][ b ]
		  else
			output[ a ][ b ] = img2[ a ][ b ]
		  end
		else
		  output[ a ][ b ] = img2[ a ][ b ]
		end
	  end
	end
  end
  return output
end
Edited on 11 April 2016 - 07:12 PM
LDDestroier #3
Posted 12 April 2016 - 12:03 AM
snip

This seems to work. Thanks!