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

Would this way of doing it be fine?

Started by Tjakka5, 27 March 2013 - 10:20 PM
Tjakka5 #1
Posted 27 March 2013 - 11:20 PM
Hey guys/girls.

I am trying to get a nice modular and compact way to show 'coordinates' on a screen, where a player can run around it.
I've done a few tests, and this was the best I could came up with.


-- "[]" = Block
-- "  " = Air
-- "##"=Player


local co1 = {"[]", "  ", "[]"}
local co2 = {"[]", "##", "  "}
local i
function printCoords()
  for i = 1, 3 do
	term.write("" ..co1[i])
  end
  print("")
  for i = 1, 3 do
	term.write("" ..co2[i])
  end
  print("")
end
function checkCoords()
  for i = 1, 3 do
	f = co1[i]
	if f == "##" then
	end
  end
  for i = 1, 3 do
	f = co2[i]
	if f == "##" then
	  movePlayerRight()
	end
  end
end

function movePlayerRight()  --Getting a error around here-ish, table index expexted, got nil
  co2[i] = " "
  co2[i+1] = "##''
end

printCoords()
checkCoords()
printCoords()


For now, this is a prototype.
I hope someone can help…
remiX #2
Posted 28 March 2013 - 12:01 AM
It's erroring because the variable 'i' isn't defined.
With something like this, you should use one table for the entire map of the area …
Something like this for example.