Jump to content




Program error.

turtle help

75 replies to this topic

#61 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 14 January 2013 - 03:35 PM

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


#62 detsuo04

  • Members
  • 35 posts

Posted 14 January 2013 - 03:37 PM

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

#63 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 14 January 2013 - 03:39 PM

same type of ore or random?

#64 detsuo04

  • Members
  • 35 posts

Posted 14 January 2013 - 03:42 PM

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.

#65 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 14 January 2013 - 03:46 PM

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...

#66 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 14 January 2013 - 03:56 PM

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.

#67 detsuo04

  • Members
  • 35 posts

Posted 14 January 2013 - 03:57 PM

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


#68 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 14 January 2013 - 04:02 PM

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....

#69 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 14 January 2013 - 04:08 PM

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

#70 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 14 January 2013 - 04:09 PM

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...

#71 detsuo04

  • Members
  • 35 posts

Posted 14 January 2013 - 04:24 PM

lol missingno attacks

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

#72 detsuo04

  • Members
  • 35 posts

Posted 15 January 2013 - 01:25 AM

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: miner.jpg


#73 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 15 January 2013 - 01:47 AM

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


#74 crazyguymgd

  • Members
  • 139 posts
  • LocationUSA

Posted 15 January 2013 - 01:55 AM

Nice job :)

#75 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 15 January 2013 - 03:09 AM

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.

#76 detsuo04

  • Members
  • 35 posts

Posted 15 January 2013 - 08:32 AM

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






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users