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

Help needed with windows and for loops

Started by The_Red_Ore, 02 November 2017 - 02:12 PM
The_Red_Ore #1
Posted 02 November 2017 - 03:12 PM
I started trying to make an uno game using computercraft,
however I was stopped very shortly because I need to fill
my monitor with 1 high 1 wide windows me being me I thought
I could do it like this however it doesn't work any help is appreciated,
I can normally do almost anything I want with computercraft,
but this seems to of thrown me this is my current code:


--initial setup
rednet.open("right")
mon = peripheral.wrap("top")
rednet.host("uno","P1")
pro = "uno"
x,y = mon.getSize()
for yy = 1, y do
  for xx = 1, x do
	yyy = tostring(yy)
	xxx = tostring(xx)
	var = yyy..","..xxx
	(var) = window.create(mon,xx,yy,1,1,true)
	(var).setBackgroundColor(colors.gray)
	(var).clear()
  end
end
Luca_S #2
Posted 05 November 2017 - 07:57 PM
First of all: Why would you fill the whole term with 1 by 1 windows. It is pretty inefficient and will probably cause your program to lag.

Also please name your variables better, you could call the return values of mon.getSize() width and height and then call the variables in the loop x and y.

To fix your problem: These parentheses around your variables seem strange:


	(var) = window.create(mon,xx,yy,1,1,true)
	(var).setBackgroundColor(colors.gray)
	(var).clear()

if you remove them it should work, however the only thing your program is going to do is make the whole monitor black which could've been accomplished using this:

mon.setBackgroundColor(colors.gray)
mon.clear()
Also you are reusing var in a strange way, first you save the x and y coordinate seperated by a "," and then you save your window, while never actually using your first value.
Another thing is that it's completely redundant to use tostring() on your x and y values before putting them together in one string because lua will do that automaticlly for you, so this would've also worked:

var = yy..","..xx
KingofGamesYami #3
Posted 05 November 2017 - 08:56 PM
This looks like a rather severe case of the xy problem.