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

[Lua]

Started by Spongy141, 16 December 2012 - 11:26 AM
Spongy141 #1
Posted 16 December 2012 - 12:26 PM
I was trying to make a program for my wireless turtle so it can turn a message I sent to it to a line, such as if I send it turtle.up() it would go up, ect. but No matter what the function wouldn't work right to do that.

function writeLine()
  local file = fs.open("file", "w")
  if file then
    file.writeLine(cmd)
    file.close()
  end
end
function runLine()
  shell.run("file")
end

rednet.open("top")
rednet.open("bottom")
rednet.open("back")
rednet.open("front")
rednet.open("right")
rednet.open("left")
while true do
  user, cmd = rednet.receive()
  writeLine()
  runLine()
end

Doyle3694 #2
Posted 16 December 2012 - 12:33 PM
loadstring(cmd)()

ofcourse you cant send "turtle.forward()" but you'll have to send just "turtle.forward" without parentheses
Spongy141 #3
Posted 16 December 2012 - 12:36 PM
loadstring(cmd)()

ofcourse you cant send "turtle.forward()" but you'll have to send just "turtle.forward" without parentheses
thanks, lol were do I put that. Im guessing in the "while true do" but Im not always right, lol.
Sammich Lord #4
Posted 16 December 2012 - 12:37 PM
loadstring(cmd)()

ofcourse you cant send "turtle.forward()" but you'll have to send just "turtle.forward" without parentheses
thanks, lol were do I put that. Im guessing in the "while true do" but Im not always right, lol.
When you receive a message put it.
Spongy141 #5
Posted 16 December 2012 - 12:38 PM
loadstring(cmd)()

ofcourse you cant send "turtle.forward()" but you'll have to send just "turtle.forward" without parentheses
thanks, lol were do I put that. Im guessing in the "while true do" but Im not always right, lol.
When you receive a message put it.
Thanks human, but the turtle still will not move, or attack, or mine… lol I put the loadstring(cmd)() after the rednet.receive, put it inside it now, and works perfectly, thanks. wow again it stop working…
ChunLing #6
Posted 16 December 2012 - 03:13 PM
Post your revised code.
Spongy141 #7
Posted 18 December 2012 - 06:11 AM
Post your revised code.
I fixed it myself, and a little help from a friend, and when I did:

loadstring(cmd)()
os.pullEvent = loadstring(cmd)()
it looped the one command I gave the turtle, and if something was in its path it crashed. But as you can see I edited it to work right, no offense but you guys weren't very good help.
NDFJay #8
Posted 18 December 2012 - 08:43 AM
nice to see you got it finised, i was going to add my little fix in there :P/>
Doyle3694 #9
Posted 18 December 2012 - 12:48 PM
Post your revised code.
I fixed it myself, and a little help from a friend, and when I did:

loadstring(cmd)()
os.pullEvent = loadstring(cmd)()
it looped the one command I gave the turtle, and if something was in its path it crashed. But as you can see I edited it to work right, no offense but you guys weren't very good help.

Yeah, really easy to help when you cant post your code… if you edit something, you got to give us the new code. You weren't very co-operative either.
ChunLing #10
Posted 18 December 2012 - 08:35 PM
It's fixed, so that's good enough.