Jump to content




[lua] problem with the if command


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

#1 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 10 May 2012 - 03:05 AM

well i made a remote command thing

shell.run("clear")
print("computer id is: "..os.getComputerID())
write("modem direction: ")
rednet.open(read())
write("controller id: ")
controller=read()
while true do
  id,data=rednet.receive()
  print("received '"..data.."' from id: '"..id.."' controller id: '"..controller.."'")
  if id == controller then
    print("executing")
    local tWords = {}
    for match in string.gmatch(data, "[^ \t]+") do
      table.insert( tWords, match )
    end
    local sCommand = tWords[1]
    if sCommand then
      shell.run( sCommand, unpack( tWords, 2 ) )
    end
print("done")
  end
end

but for some reason id == controller wont return true when it displays "received 'something' from id: '0' controller id: '0'"

:C

#2 Xtansia

  • Members
  • 492 posts
  • LocationNew Zealand

Posted 10 May 2012 - 03:37 AM

Because id returned by rednet.receive() is a number while controller returned by read() is a string, This is easily fixed by changing:
controller = read()
To:
controller = tonumber(read())


#3 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 10 May 2012 - 05:17 PM

oh god thank you
i just learned the basics of lua and this will help me alot





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users