17 posts
                
                    
                        Location
                        6 feet under.. the void ^^
                    
                
             
            
                Posted 27 March 2012 - 05:04 PM
                So.. I tried to create a program that builds me a platform at a ratio of 2:1
its not working.. can anyone take a peek and check if something is wrong?
Spoiler
term.clear()
term.setCursorPos(1,1)
print("Area?")
o=read()
o=b
a=tonumber(o)
b=tonumber(o)/2
x=0
y=0
s=1
while y<b do
y=y+1
  while x<a do
   turtle.forward()
   turtle.placeDown()
	  if turtle.getSlotcount()==0 then
	  s=s+1
	  turtle.selectSlot("s")
	  else
	end
q=bit.band(y, 1)
	if q==("1") then
	   turtle.turnRight()
	   turtle.forward()
	   turtle.turnRight()
	elseif q==("0") then
	   turtle.turnLeft()
	   turtle.forward()
	   turtle.turnLeft()
end
end  
 
                
             
         
        
        
            
            
                
                    
                
                17 posts
                
                    
                        Location
                        6 feet under.. the void ^^
                    
                
             
            
                Posted 27 March 2012 - 05:35 PM
                Oh my.. i double posted..i double posted.. how silly
Can a mod just close the twin? plz and TY
                
             
         
        
        
            
            
                
                    
                
                80 posts
                
             
            
                Posted 27 March 2012 - 05:42 PM
                1. Post the error.
2. What is o=b doing?
3. It should be turtle.select(s), not turtle.select("s"). You want to use the variable s, not the string "s".
4. It should be turtle.getItemCount(s), not turtle.getSlotcount().
                
             
         
        
        
            
            
                
                    
                
                1604 posts
                
             
            
                Posted 27 March 2012 - 05:55 PM
                There's some errors in the code, I added some comments so you can fix them:
term.clear()
term.setCursorPos(1,1)
print("Area?")
o = read()
o = b -- b is nil, now o is nil also, user input lost
a = tonumber(o)
b = tonumber(o) / 2 -- shorter way: b = a / 2
x = 0
y = 0
s = 1
while y < b do -- it could be a for loop: for y = 0, b do
	y = y + 1 -- remove if using for
	while x < a do -- infinite loop, x never changes
		turtle.forward()
		turtle.placeDown()
		if turtle.getSlotcount() == 0 then -- getSlotcount doesn't exists, it's getItemCount
			s = s + 1
			turtle.selectSlot("s") -- "s" is a string, remove the quotes to use the variable
		else -- else what?
		end
		q = bit.band(y, 1)
		if q == ("1") then -- q is a number, "1" is a string, q will never be "1"
			turtle.turnRight()
			turtle.forward()
			turtle.turnRight()
		elseif q == ("0") then -- same as above
			turtle.turnLeft()
			turtle.forward()
			turtle.turnLeft()
		end
	end
-- end missing
You should also try to use local variables when possible:
local n = 10
local o = read()
And try to indent the code to check that all the end's are in the right place.
 
                
             
         
        
        
            
            
                
                    
                
                17 posts
                
                    
                        Location
                        6 feet under.. the void ^^
                    
                
             
            
                Posted 27 March 2012 - 06:15 PM
                Lol ok i made some adjustments.. (havnt checked the code that mystic T posted yet)
heres the new code
Spoiler
term.clear()
term.setCursorPos(1,1)
print("how wide?")
a=tonumber(read())
term.setCursorPos(1,3)
term.clearLine()
print("how long")
b=tonumber(read())
x=0
y=0
s=1
while y<b do
y=y+1
  while x<a do
x=x+1
   turtle.forward()
   turtle.placeDown()
	if turtle.getItemCount(s)==0 then
	  s=s+1
	  turtle.selectSlot(s)
	  else
	end
x=0
q=tonumber(y)
if q%2==1 then
turtle.turnRight()
turtle.forward()
turtle.turnRight()
elseif q%2==0 then
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
else
break
end
end
end
term.clear()
term.setCursorPos(1,1)
print("done")
i added a x=x+1 and fixed some errors but now it runs in circles :o/>/>
EDIT.. haha thx mystic.. mind checking the new one.. i have a feeling one of my ends are totally misplaced
 
                
             
         
        
        
            
            
                
                    
                
                17 posts
                
                    
                        Location
                        6 feet under.. the void ^^
                    
                
             
            
                Posted 27 March 2012 - 06:28 PM
                aaah i found it.. moved a end .. made it easier for myself by making it a bit easier to read
here it is dunno if it works yet 
Spoiler
term.clear()
term.setCursorPos(1,1)
print("how wide?")
a=tonumber(read())
term.setCursorPos(1,3)
term.clearLine()
print("how long")
b=tonumber(read())
turtle.placeDown()
x=0
y=0
s=1
  while y<b do
   y=y+1
	while x<a do
	x=x+1
		turtle.forward()
		turtle.placeDown()
		   if turtle.getItemCount(tonumber(s))==0 then
		   s=s+1
		   turtle.selectSlot(tonumber(s))
		   end	
end
x=0
q=tonumber(y)
		 if q%2==1 then
			turtle.turnRight()
			turtle.forward()
turtle.placeDown()
			turtle.turnRight()
		 elseif q%2==0 then
			turtle.turnLeft()
			turtle.forward()
turtle.placeDown()
			turtle.turnLeft()
		 end
end
term.clear()
term.setCursorPos(1,1)
print("done")
works great.. i just needed to add a turtle.placeDown() after the turns.
Woot.. time to create a superflat over a survival
ok.. stoped at a empty slot..
figured out turtle.selectSlot(slotNum) us WRONG..
use turtle.select(slotNum)