←  Ask a Pro

ComputerCraft | Programmable Computers for Minecraft

»

Program error.

theoriginalbit's Photo theoriginalbit 14 Jan 2013

ahhh ok... i suggest inverting the returns in value() then... have it return true, indicating it can mine it, and false indicating it can't... then when using value() do
if value() then dig() else somethingElse() end
Quote

detsuo04's Photo detsuo04 14 Jan 2013

wait i take it back. it almost works. for some reasone it skips an ore occationaly
Quote

theoriginalbit's Photo theoriginalbit 14 Jan 2013

same type of ore or random?
Quote

detsuo04's Photo detsuo04 14 Jan 2013

it would have to be random. since the program only identifies slot 1 2 and 3 of its inv which has dirt stone and gravel.
im thinking its skiping a compare one one or more of its turns.

edit
it skips ores on its back and left side reletive to starting orientation.
Quote

theoriginalbit's Photo theoriginalbit 14 Jan 2013

hmmm not too sure... I'll have a look in a minute...

also what with your random

do

end

inside your while loop, you don't need to localise that code... you can remove that do end statement...
Quote

crazyguymgd's Photo crazyguymgd 14 Jan 2013

In your walls function:


function walls()
  for j = 1,4 do
    print("value function")
    if value() then
      turtle.dig()
      rn (base, "ore collected at "..z.." ")
    else
      turtle.turnRight()
    end
  end
end
Lets say there is an ore when j = 1, the value function will return true, you'll dig the ore, sit still, then j increments to 2. Then value will return false, you'll turn right, and j increments to 3. say there is another ore here (we're only on the second wall at this point). value will return true, you'll dig, and then j will increment to 4. Value returns false, you turn right, but now the for loop is done, walls() returns and you never actually check the back or left wall.
Thats a scenario I imagined that could cause this problem. There are probably plenty more.
To solve this, turn right when value() returns true and when it returns false. So you will at least always check every wall.
Quote

detsuo04's Photo detsuo04 14 Jan 2013

View PostTheOriginalBIT, on 14 January 2013 - 03:46 PM, said:

hmmm not too sure... I'll have a look in a minute...

also what with your random

do

end

inside your while loop, you don't need to localise that code... you can remove that do end statement...
you meen here?

edit: i added a turn right command after it collects ore so that should fix that. thanks
while true do
  print("2")
  f = turtle.getFuelLevel()
  if f < z + 10 then
	rn (base , "Danger! fuel levels low.")
	turtle.select(16)
	turtle.refuel()
	z = turtle.getFuelLevel()
	if f < z + 10 then
	  rn (base , "Insuficient Coal, Returning.")
	  home()
	end
Quote

theoriginalbit's Photo theoriginalbit 14 Jan 2013

View Postdetsuo04, on 14 January 2013 - 03:57 PM, said:

you meen here?
while true do
  print("2")
  f = turtle.getFuelLevel()
  if f < z + 10 then
	rn (base , "Danger! fuel levels low.")
	turtle.select(16)
	turtle.refuel()
	z = turtle.getFuelLevel()
	if f < z + 10 then
	  rn (base , "Insuficient Coal, Returning.")
	  home()
	end
the do is required for the while... but when I looked at your completed code post before a wild 'do end' has appeared....
Quote

crazyguymgd's Photo crazyguymgd 14 Jan 2013

View Postdetsuo04, on 14 January 2013 - 03:57 PM, said:

edit: i added a turn right command after it collects ore so that should fix that. thanks

ok let me know how that goes
Quote

crazyguymgd's Photo crazyguymgd 14 Jan 2013

View PostTheOriginalBIT, on 14 January 2013 - 04:02 PM, said:

the do is required for the while... but when I looked at your completed code post before a wild 'do end' has appeared....

I'm having a hard time not photoshopping an image of this pokemon battle...
Quote

detsuo04's Photo detsuo04 14 Jan 2013

lol missingno attacks

it worked all opperations are good. still have to check the out of fuel operation though.
Quote

detsuo04's Photo detsuo04 15 Jan 2013

The results of my hard labor

Lil Cal and Lil Hal both running my program in tandom.

Thanks for all the help guys!!!

Attached Thumbnails

  • Attached Image
Quote

theoriginalbit's Photo theoriginalbit 15 Jan 2013

View Postdetsuo04, on 15 January 2013 - 01:25 AM, said:

The results of my hard labor

Lil Cal and Lil Hal both running my program in tandom.

Thanks for all the help guys!!!

VERY cool :) No problems...

An extra coding challenge if you dare:
Spoiler
Quote

crazyguymgd's Photo crazyguymgd 15 Jan 2013

Nice job :)
Quote

remiX's Photo remiX 15 Jan 2013

View PostTheOriginalBIT, on 15 January 2013 - 01:47 AM, said:

An extra coding challenge if you dare:
Spoiler

Yeah, he could have the max sized monitor and split it into two which Lil Cal on top and Lil Hal on the bottom, or left and right.
Quote

detsuo04's Photo detsuo04 15 Jan 2013

thats some cool stuff. i think i will however first i need to revuild my base deeper into the earth. thousands of spiders keep screaming at me through the roof and zombies keep knocking like sales guys....

im wrighting a program now to tunnel out a room with player imputed variabls for x y and z

edit:

and the code is done. there is a moment where lil hal mines x to the end and comes back then he goes up z and mines x again.. then oddly he skips his up z step and runs the middle x again. after that he comtinues up and finishes the program.

he re runs the x on z 2 for every y. weired. anyway here is the code.

fixed :P

rednet.open("right")
print("Room clearing program")
sleep(1)
print("What is my base id: ")
a = tonumber(read())
rn = rednet.send
rn (a , "connection established")
print ("what is the rooms length (forward)?")
x = tonumber(read())
print ("ok. Now the width (right)?")
y = tonumber(read())
print ("ok. And finaly the hight (up)?")
z = tonumber(read())
rn (a , "the room will be "..x.." long,")
rn (a , " "..y.." wide,")
rn (a , "and "..z.." tall.")
--======paramiters of room are set=======--
print ("Is the size right? ")
b = read()
  if b ~= "yes" then
  os.shutdown()
  end
	f = turtle.getFuelLevel()
	rn (a , "fuel is "..f.." units.")
	need = (x*y*z) + x + y + z
	rn (a , "assignment needs "..need.." fuel")
	if f < need then
	  rn (a , "incificient fuel for assignment")
	  os.shutdown()
	end
  x2 = 1
  y2 = 0
  z2 = 1
  done = 0
  l = 0
while l == 0 do
  while y2 ~= y do
	while z2 ~= z do
	  while x2 ~= x do
		turtle.dig()
		turtle.forward()
		x2 = x2 +1
	  end
		while x2 ~= 1 do
		  turtle.back()
		  x2 = x2 - 1
		end
	  if z2 ~= z then
		turtle.digUp()
		turtle.up()
		z2 = z2 + 1
	  end
	  while x2 ~= x and z2 == z do
		turtle.dig()
		turtle.forward()
		x2 = x2 + 1
	  end
	  while x2 ~= 1 and z2 == z do
		turtle.back()
		x2 = x2 - 1
	  end
	end

	while z2 ~= 1 do
	  turtle.down()
	  z2 = z2 - 1
	end
  
	if y2 ~= y and l == 0 then
	  turtle.turnRight()
	  turtle.dig()
	  turtle.forward()
	  turtle.turnLeft()
	  y2 = y2 + 1
	end
  end
  l = 1
end
Quote