Jump to content




Forcefield program not working (rednet)

computer wireless

5 replies to this topic

#1 graywolf69

  • Members
  • 44 posts

Posted 05 February 2015 - 03:32 PM

I wrote a program yesterday and it isn't working. Basically it sends an off or on command to a computer that turns the forcefield on or off. Problem is I can turn the forcefield on but not off. I've gone through it 3-4 times and couldn't figure out what was wrong, I even copied and pasted the off command and just changed some of the parts and it didn't work. Help is greatly appreciated!

Code:

Sending program: http://pastebin.com/F0j9TugB

Receiving program: http://pastebin.com/ApL20f1t

#2 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 05 February 2015 - 03:50 PM

At first glance, I think this is the problem

if message == forceon then --#Line 12 from the receiving program

Should be

if message == "forceon" then

without the quotes, its a variable, but with the quotes, its a string.

#3 graywolf69

  • Members
  • 44 posts

Posted 05 February 2015 - 04:22 PM

Nope, force on works, it's force off that doesn't. Also I wrote everything this way and the other stuff works.

Edited by graywolf69, 05 February 2015 - 04:23 PM.


#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 05 February 2015 - 04:53 PM

Here, I rewrote your program(s) to reflect what it is actually doing:

Spoiler

Spoiler

Since you either send it nil or nil, message will always equal nil in the first statement. Basically, when you think you are telling it to turn off, you are telling it to turn on.

Edit2: If you don't believe me, run this:

if forceon == forceoff then
   print( "They are equal!" )
else
   print( "They are not equal!" )
end

Edited by KingofGamesYami, 05 February 2015 - 05:00 PM.


#5 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 05 February 2015 - 04:56 PM

View PostKingofGamesYami, on 05 February 2015 - 04:53 PM, said:

Here, I rewrote your program to reflect what it is actually doing:

Spoiler

Haha, was just about to post the fix.

To clarify, you need to use "" (quotation marks) around the messages. If you don't, it just uses the variable, which is nil since you never initialized them.

#6 graywolf69

  • Members
  • 44 posts

Posted 05 February 2015 - 11:57 PM

Thank you so much, it worked!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users