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

[HELP!] Why does this say this? (3RD error + Question)

Started by Velthos, 17 September 2012 - 04:59 PM
Velthos #1
Posted 17 September 2012 - 06:59 PM
So I'm trying to make a script like eloraam did in Direwolf20's SMP Lets Play series. I think most of my script works but it says

The old code + error is:
SpoilerTurtle:18:Expected Number


os.pullEvent = os.pullEventRaw

local slot
local times

turtle.select(slot)
slot = 1
function check()
  if turtle.getItemCount(slot) == 0 then
	print("Changing Stack.")
	slot = slot + 1
	turtle.select(slot)
	if turtle.getItemCount(slot) == 0 then
	  print("No more items. Please keep all items together.")
	end
  end
end

function up()
  turtle.up()
end

function down()
  turtle.down()
end

function go()
  turtle.forward()
end

function left()
  turtle.turnLeft()
end

function right()
  right = turtle.turnRight()
end

term.clear()
term.setCursorPos(1,1)

print("Please place fuel in the highlighted area.")
print(" ")
print("Please place building materials in non-highlighted areas.")
print(" ")
print("Please remember that each 'set' of blocks is 7.")

sleep(5)

term.clear()
term.setCursorPos(1,1)

print("How far should the path go?")
print("")
times = tonumber(io.read())

sleep(2)

print("")
print("Going " ..times.. " blocks.")

for i = 1, times, 1 do --times()
  go()
  left()
  go()
  go()
  turtle.placeDown()
  check()
  up()
  turtle.placeDown()
  check()
  right()
  right()
  go()
  down()
  turtle.placeDown()
  check()
  for j = 1, 3 do
	go()
	turtle.placeDown()
	check()
  end
  up()
  turtle.placeDown()
  check()
  left()
  left()
  go()
  go()
  right()
  down()  
end
SpoilerThe 2nd code + error is:

path:77: attempt to call boolean



os.pullEvent = os.pullEventRaw

turtle.refuel(64)

local times
local slot = 1
turtle.select(slot)
slot = 1
function check()
  if turtle.getItemCount(slot) == 0 then
	print("Changing Stack.")
	slot = slot + 1
	turtle.select(slot)
	if turtle.getItemCount(slot) == 0 then
	  print("No more items. Please keep all items together.")
	end
  end
end

function up()
  turtle.up()
  sleep(1)
end

function down()
  turtle.down()
  sleep(1)
end

function go()
  turtle.forward()
  sleep(1)
end

function left()
  turtle.turnLeft()
  sleep(1)
end

function right()
  right = turtle.turnRight()
  sleep(1)
end

term.clear()
term.setCursorPos(1,1)

print("Please place fuel in the highlighted area.")
print(" ")
print("Please place building materials in non-highlighted areas.")
print(" ")
print("Please remember that each 'set' of blocks is 7.")

sleep(5)

term.clear()
term.setCursorPos(1,1)

print("How far should the path go?")
print("")
times = tonumber(io.read())

sleep(2)

print("")
print("Going " ..times.. " blocks.")

for i = 1, times, 1 do
  go()
  left()
  go()
  go()
  up()
  turtle.placeDown()
  check()
  right()
  right()
  go()
  down()
  turtle.placeDown()
  check()
  for j = 1, 2 do
	go()
	turtle.placeDown()
	check()
  end
  go()
  up()
  turtle.placeDown()
  check()
  left()
  left()
  go()
  go()
  right()
  down()  
end


The newest code/error is to do with rednet. (Keep on mind that this is on a turtle!)

Error: path:11: attempt to call nil



os.pullEvent = os.pullEventRaw

local timeout = 1000000
local times
local slot = 1
turtle.select(slot)
slot = 1
local id = 0

rednet.open("right")
rednet.recieve(timeout) -- Line 11

function check()
  if turtle.getItemCount(slot) == 0 then
    print("Changing Stack.")
    slot = slot + 1
    turtle.select(slot)
    if turtle.getItemCount(slot) == 0 then
      print("No more items. Please keep all items together. Carrying on in 120 seconds.")
      sleep(120)
    end
  end
end

function up()
  turtle.up()
  sleep(.5)
end

function down()
  turtle.down()
  sleep(.5)
end

function go()
  turtle.forward()
  sleep(.5)
end

function left()
  turtle.turnLeft()
  sleep(.5)
end

function right()
  turtle.turnRight()
  sleep(.5)
end

term.clear()
term.setCursorPos(1,1)

print("Please place fuel in the highlighted area.")
print(" ")
print("Please place building materials in non-highlighted areas.")
print(" ")
print("Please remember that each 'set' of blocks is 7.")

sleep(5)

turtle.refuel(64)

term.clear()
term.setCursorPos(1,1)

print("How far should the path go?")
print("")
if times == nil then
times = tonumber(io.read())
end

if times == 999 then
error()
end

if times == 0 then
  up()
  down()
  left()
  right()
  go()
  left()
  left()
  go()
  right()
  right()
  else

  sleep(2)

  print("")
  print("Going " ..times.. " blocks.")

  for i = 1, times, 1 do
    go()
    left()
    go()
    go()
    turtle.placeDown()
    turtle.placeDown()
    check()
    up()
    turtle.placeDown()
    check()
    right()
    right()
    go()
    down()
    turtle.placeDown()
    check()
    for j = 1, 3 do
      go()
      turtle.placeDown()
      check()
    end
    up()
    turtle.placeDown()
    check()
    left()
    left()
    go()
    go()
    right()
    down()  
  end
end

shell.run("path")


Also. How would I go about creating a GPS tower for when my turtle is further away from my main system.
MysticT #2
Posted 17 September 2012 - 07:05 PM
You didn't initialize the slot variable, so it's nil and the turtle.select function requires a number. Try setting it to 1 before using turtle.select:

local slot = 1

turtle.select(slot)
GopherAtl #3
Posted 17 September 2012 - 07:07 PM
you pass slot to turtle.select before initializing it on line… 6-ish, at the top.

:Edit: damn, lot of ninjas here today haha.
Velthos #4
Posted 17 September 2012 - 07:36 PM
New error. Please help :)/>/>
GopherAtl #5
Posted 17 September 2012 - 07:40 PM
right() function sets right=turtle.turnRight(). In the lua world, this means it replaces the function right with the boolean value returned by turnRight. You don't seem to be using it anyway, so just remove the right= from that function.

:edit: and this time I am the ninja. score's 1:1, mystic :)/>/>
MysticT #6
Posted 17 September 2012 - 07:42 PM
In your right function you do:

right = turtle.turnRight()
wich overwrites the function with the return value of turtle.turnRight() (wich is a boolean).
If you don't use that return value, just remove the "right =" part:

local function right()
  turtle.turnRight()
  sleep(1)
end

Edit: too slow this time :)/>/>
Velthos #7
Posted 17 September 2012 - 07:43 PM
Thanks to both of you.

I still don't exactly understand what a boolean value is
GopherAtl #8
Posted 17 September 2012 - 07:44 PM
heh, you were right, it's just a true/false value :)/>/>
MysticT #9
Posted 17 September 2012 - 07:45 PM
Thanks to both of you.

I still don't exactly understand what a boolean value is
A boolean is a value that can be either true or false. It's mostly used for conditionals (if statements) and loops (while or repeat).
Velthos #10
Posted 17 September 2012 - 08:05 PM
For some reason the first block its meant to place, it skips and moves to the second. If I try to place one before hand to try and fix it, it doesn't work.

EDIT:
Never mind, I just had to reposition the extra turtle.placeDown() to right next to the first one its meant to place. Works now :)/>/>
Velthos #11
Posted 17 September 2012 - 08:51 PM
Another question, sorry for double post but I really need to get back into lua coding. Last time I properly coded like this was about 2 years ago :)/>/>

Off for the night, will say thanks in the morning.
MysticT #12
Posted 17 September 2012 - 08:55 PM
Simple typo:

rednet.recieve(timeout)
should be:

rednet.receive(timeout)