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

Lock please.

Started by Silverrune, 20 December 2012 - 05:29 PM
Silverrune #1
Posted 20 December 2012 - 06:29 PM
I figured it out.
Edited by
Dlcruz129 #2
Posted 20 December 2012 - 06:35 PM
I am trying to imitate sethbling's code for "build" which is a mob trap creator.
Spoiler

slot = 2
local function setSlot(s)
  slot = s
  turtle.select(s)
end
local function checkFuel()
  curSlot = slot
  if turtle.getFuelLevel() < 10 then
	setSlot(1)
	turtle.refuel()
	setSlot(curSlot)
  end
end
local function digMove()
  checkFuel()
  if turtle.forward() then
	return true
  end
  for i=1,100 do
	if turtle.dig() then
	  if turtle.forward() then
		return true
	  end
	end
  end
  for i=1,100 do
	if turtle.forward() then
	  return true
	end
	turtle.attack()
  end

  return false
end
local function digMoveUp()
  turtle.digUp()
  checkFuel()
  return turtle.up()
end
local function digMoveDown()
  turtle.digDown()
  checkFuel()
  return turtle.down()
end
local function selectStack()
  if turtle.getItemCount(slot) > 0 then
	return
  end
  for s = 2,16 do
	if turtle.getItemCount(s) > 0 then
	  if s ~= slot then
		setSlot(s)
	  end
	  return
	end
  end
end
local function place()
  selectStack()
  turtle.place()
end
local function placeUp()
  selectStack()
  turtle.placeUp()
end
local function placeDown()
  selectStack()
  turtle.placeDown()
end
function vcoords(x, y, z, w, h, d)
  local fy = h+1-y
  local parity = 0
  if d%2==1 and y%2==0 then
	parity = 1
  end
  local fz = z
  if y%2==0 then
	fz = d+1-z
  end
  local fx = x
  if z%2==parity then
	fx = w+1-x
  end

  return fx,fy,fz
end

local function buildBox(w, h, d, buildFunc)
  for y=1,h do
	local skipX = 1
	if y ~= 1 then
	  turtle.turnRight()
	  turtle.turnRight()
	  digMoveDown()
	end
	for z=1,d do
	  if z ~= 1 then
		local parity = 0
		if d%2 == 0 and y%2==0 then
		  parity = 1
		end
		if z%2 == parity then
		  turtle.turnRight()
		  digMove()
		  turtle.turnRight()
		else
		  turtle.turnLeft()
		  digMove()
		  turtle.turnLeft()
		end
	  end
	  for x=skipX,w do
		if x ~= skipX then
		  digMove()
		end
		turtle.digDown()
	  
		local fx, fy, fz
		fx,fy,fz = vcoords(x,y,z,w,h,d)
		if buildFunc(fx, fy, fz) then
		  placeUp()
		end
	  
		local skip = true
		if z<d then
		  skipX = 0
		  for tx=x+1,w do
			local tfx,tfy,tfz
			tfx,tfy,tfz=vcoords(tx,y,z,w,h,d)
			if buildFunc(tfx,tfy,tfz) then
			  skip = false
			  break
			end
			tfx,tfy,tfz=vcoords(tx,y,z+1,w,h,d)
			if buildFunc(tfx,tfy,tfz) then
			  skip = false
			  break
			end
		  end
		  if skip then
			skipX = w+1-x
			break
		  end
		end
	  end
	end
  end
end
local function column(x, y, z)
  if x==2 and z==2 then
	return true
  else
	return false
  end
end
local function mobTrap(w, h, d)
  return function(x, y, z)
	if y >= h-1 then
	  if x == 1 or x == w or z == 1 or z == d then
		return true
	  else
		return false
	  end
	end
	d1 = (x-1) + (z-1)
	d2 = (w-x) + (z-1)
	d3 = (x-1) + (d-z)
	d4 = (w-x) + (d-z)
	minD = math.min(math.min(d1, d2), math.min(d3, d4))
	level = math.floor(minD / 7)
	if h-2-y == level then
	  return true
	elseif (x==1 or z==1 or x==w or z==d) and (h-2-y < level) then
	  return true
	else
	  return false
	end
  end
end
buildBox(70, 25, 70, mobTrap(70, 25, 70))
I get the error "bios:338: [string "build"]:126: 'in' expected"
What is wrong? I would love a quick reply as I want to try and run this overnight.

I ain't counting to line 126 for you. Please put it on Pastebin, or show us the line that errors.
theoriginalbit #3
Posted 20 December 2012 - 06:36 PM
Please use pastebin for long code, it has line numbers and makes our job so much nicer, we dont like to count. :P/>

EDIT: haha Dlcruz129 beat me to it. lol
Lyqyd #4
Posted 20 December 2012 - 06:37 PM
You guys really can't copy/paste to your favorite text editors? Sheesh.

OP, I'm not seeing anything at line 126 that should need an "in". I'm really not sure why it would be erroring like that. Did you end up having to type this all in to computercraft? There may be a typo there causing the error.
Dlcruz129 #5
Posted 20 December 2012 - 06:38 PM
You guys really can't copy/paste to your favorite text editors? Sheesh.

OP, I'm not seeing anything at line 126 that should need an "in". I'm really not sure why it would be erroring like that. Did you end up having to type this all in to computercraft? There may be a typo there causing the error.

iPhone…
theoriginalbit #6
Posted 20 December 2012 - 06:40 PM
You guys really can't copy/paste to your favorite text editors? Sheesh.

I could, but it takes time to highlight it, would you expect us to do it with a 1000 line code. no you wouldn't. they are copy pasting it anyways, an extra step isn't going to kill them. Also the other issue with copy paste into a text editor from here is here doesn't preserve white space meaning line 126 is probably missing an in, but we cant see it because it may actually be line 80 without whitespace.
Lyqyd #7
Posted 20 December 2012 - 06:50 PM
The forums do seem to preserve line breaks relatively well, though. I dunno, just seems really pretty easy to quickly select the code and copy/paste it into a text editor. Eh. I was just teasing you guys, but neglected to append an emoticon to signify such. ;)/>
ChunLing #8
Posted 20 December 2012 - 06:53 PM
Pastebin is also a good solution for avoiding typos and copying errors, if that's the source of the problem.
Lyqyd #9
Posted 20 December 2012 - 06:56 PM
Don't edit your posts to remove the content. Don't edit your title to request a lock.

Please post the answer you found so that others with a similar question can find the answer without needing to ask.
theoriginalbit #10
Posted 20 December 2012 - 06:57 PM
Don't edit your posts to remove the content. Don't edit your title to request a lock.

How does one actually request a lock?
Lyqyd #11
Posted 20 December 2012 - 06:59 PM
Don't edit your posts to remove the content. Don't edit your title to request a lock.

How does one actually request a lock?

The best way is the Report button on each post. The original poster simply has to click that (usually for the original post in the topic, but not necessarily) and request a lock. It's best to provide a reason (discontinued project, conversation moved to a new topic, etc.). If the moderator handling that report agrees that a lock is appropriate, the topic will be locked. This procedure should also be used to request a topic be moved. The report feature should also be used (of course) to report inappropriate content.
theoriginalbit #12
Posted 20 December 2012 - 07:04 PM
snip

The best way is the Report button on each post. The original poster simply has to click that (usually for the original post in the topic, but not necessarily) and request a lock. It's best to provide a reason (discontinued project, conversation moved to a new topic, etc.). If the moderator handling that report agrees that a lock is appropriate, the topic will be locked. This procedure should also be used to request a topic be moved. The report feature should also be used (of course) to report inappropriate content.

I had a feeling it was that but wasn't sure. thanx.