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

Curious to why this isn't doing anything

Started by popdog15, 30 March 2013 - 06:39 PM
popdog15 #1
Posted 30 March 2013 - 07:39 PM
Client code:
http://www.pastebin.com/YL0DARc6
Spoiler

rednet.open("top",true)
args = {...}

  rednet.send(1, args[1])
  rednet.send(1, args[2])

Turtle code:
http://pastebin.com/5429xBk
SpoilerSorry for no comments!

[CODE]
while true do
rednet.open("right", true)
amount = 0

h = fs.open("recall", "w")
senderId, command = rednet.receive()
senderId, direction = rednet.receive()
if command == "go" and direction == "forward" then
  turtle.forward()
   h.writeLine("forward")
   amount = amount+1
end

if command == "recall" then
  recall()
end
if command == "turn" and direction == "left" then
turtle.turnLeft()
  h.writeLine("left")
  amount = amount+1
elseif command == "turn" and direction == "right" then
turtle.turnRight()
h.writeLine("right")
amount = amount+1
elseif command == "turn" and direction == "backwards" then
turtle.turnRight()
turtle.turnRight()
  amount = amount+1
   h.writeLine("backward")
   end
  
function recall()
	rcl = fs.open("recall", "r")
   if rcl.readLine(amount) == "forward" or rcl.readLine() == "backwards" then
	turtle.turnRight()
	turtle.turnRight()
	 amount = amount-1
   elseif rcl.readLine(amount) == "left" then
	turtle.turnRight()
	amount = amount-1
   elseif rcl.readLine(amount) == "right" then
   turtle.turnLeft()	  
   amount= amount-1
end
end
end

The problem;

When I try and call the recall function it does nothing. No error. Nothing.I know the rednet signal is going, because I can use any of the other functions and it works correctly.
(Since there's no comments, I'll try and explain here. The recall function tries to make the turtle "retrace" its steps. I know the turning, moving and whatnot isn't perfected yet- but that's not the problem. Yet.)
faubiguy #2
Posted 30 March 2013 - 07:52 PM
When you open the file in recall, nothing has actually been written to the file because you haven't called file.close. In the main part, Instead of opening the file once per loop, I'd probably open it each time a command needs to be added (in append mode), write the command, and close it
Immediately after. (also close it in recall after reading from it)

You may want to reset the file contents at the end of recall, which can be done by opening the file in write mode then closing it again
popdog15 #3
Posted 31 March 2013 - 11:18 AM
I reset it, and closed the file, though it still doesn't work. :\