Jump to content




[Lua]


  • You cannot reply to this topic
9 replies to this topic

#1 Spongy141

  • Members
  • 526 posts
  • Location'Merica

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



#2 Doyle3694

  • Members
  • 815 posts

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

#3 Spongy141

  • Members
  • 526 posts
  • Location'Merica

Posted 16 December 2012 - 12:36 PM

View PostDoyle3694, on 16 December 2012 - 12:33 PM, said:

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.

#4 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 16 December 2012 - 12:37 PM

View PostSpongy141, on 16 December 2012 - 12:36 PM, said:

View PostDoyle3694, on 16 December 2012 - 12:33 PM, said:

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.

#5 Spongy141

  • Members
  • 526 posts
  • Location'Merica

Posted 16 December 2012 - 12:38 PM

View PostHuman, on 16 December 2012 - 12:37 PM, said:

View PostSpongy141, on 16 December 2012 - 12:36 PM, said:

View PostDoyle3694, on 16 December 2012 - 12:33 PM, said:

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

#6 ChunLing

  • Members
  • 2,027 posts

Posted 16 December 2012 - 03:13 PM

Post your revised code.

#7 Spongy141

  • Members
  • 526 posts
  • Location'Merica

Posted 18 December 2012 - 06:11 AM

View PostChunLing, on 16 December 2012 - 03:13 PM, said:

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.

#8 NDFJay

  • Members
  • 216 posts
  • LocationLeeds, England

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

#9 Doyle3694

  • Members
  • 815 posts

Posted 18 December 2012 - 12:48 PM

View PostSpongy141, on 18 December 2012 - 06:11 AM, said:

View PostChunLing, on 16 December 2012 - 03:13 PM, said:

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.

#10 ChunLing

  • Members
  • 2,027 posts

Posted 18 December 2012 - 08:35 PM

It's fixed, so that's good enough.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users