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

Need help with a loop which in turn uses http.post

Started by LostDucks, 11 December 2016 - 07:21 PM
LostDucks #1
Posted 11 December 2016 - 08:21 PM
I really need help, as I am new to lua coding I really can't trial and error through this code
(I'm currently on a mobile device and I can't find the button which has that bbcode thing)

while true do
redstone.getInput("left") == true
then
http.post("http://example.com/eg.php?message=On")
else
http.post("http://example.com/eg.php?message=Off")
end
end

I did try to use it without "while true do" and it worked but I need a loop in this case for it to be checked
Lyqyd #2
Posted 11 December 2016 - 08:33 PM
You should have it only do something when the redstone state changes, which you can do by throwing a simple os.pullEvent("redstone") in there. You'll also need to add the if keyword, but that should be all you need to do to get it working. The final code would look like:


while true do
  if rs.getInput("left") then
    http.post(on) --# replace with actual call
  else
    http.post(off) --# replace
  end
  os.pullEvent("redstone")
end
LostDucks #3
Posted 12 December 2016 - 08:03 PM
Thank You, The code worked perfectly