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

Help with modems and wifi...

Started by MightyTurtle, 29 August 2012 - 02:45 PM
MightyTurtle #1
Posted 29 August 2012 - 04:45 PM
I am pretty much a beginner at Lua and ComputerCraft but I have some experience with Lua…
I am making a WiFi program for my friends server but i am having troubles. So far i have looked at the APIs and the ComputerCraft wiki and made it so you can see your messages and respond to them. Right now whenever you type in anything after the initial wifi (which is the programs name) it prints "Turn on your wifi." Please help i can not figure it out. I also realize some one probably had made this before and i could just take theirs but I want to do it myself. I am most likely going to post on this thread more asking for more help so please no hate.


term.clear()
term.setCursorPos(1,1)
local input = read()

–TurnOnWiFi
if input == "TurnOnWiFi" or input == "WiFiOn" then
print("Make sure your modem is on top of your computer or else it wont work. Thanks!")
rednet.open("top")
end

–SeeMessages
if rednet.open("top") == true then
repeat
local event,p1,p2,p3 = os.pullEvent
if event =="rednet_message" then
print("*Message* From: "..p1.."Message:"..p2)
print("To Message back type Respond")
end
until event =="char" and p1=="x"
–Respond
if input == "Respond" then
term.clear()
term.setCursorPos(1,1)
rednet.send(p1, input)
end
else
sleep(5)
print("Turn on your WiFi")
end


also the comments are mostly for me to see where the thing is happening.
MightyTurtle #2
Posted 29 August 2012 - 04:47 PM
Sorry i don't know how to make a code tab.
wilcomega #3
Posted 29 August 2012 - 06:01 PM
if rednet.open("top") == true then

that wont work. you gotta find another way :)/>/>
wilcomega #4
Posted 29 August 2012 - 06:03 PM
and os.pullEvent should be os.pullEvent()
and you have to do this:
print("*Message* From: "..tostring(p1).."Message:"..p2)
MightyTurtle #5
Posted 29 August 2012 - 06:19 PM
thanks…. can you tell me how to put a code tag so i can put the new code?
wilcomega #6
Posted 29 August 2012 - 06:26 PM
met
 en 
zonder spaties
MightyTurtle #7
Posted 29 August 2012 - 06:29 PM
Thanks i hope i did this right…
i changed it and it still has the same problem




term.clear()
term.setCursorPos(1,1)
local input = read()
wifi = false

--TurnOnWiFi
if input == "TurnOnWiFi" or input == "WiFiOn" then
   print("Make sure your modem is on top of your computer or else it wont work. Thanks!")
   rednet.open("top")
   wifi = true
end

--SeeMessages
if wifi then
   repeat
      local event,p1,p2,p3 = os.pullEvent()
      if event =="rednet_message" then
         print("*Message* From: "..p1.."Message:"..p2)
         print("To Message back type Respond")
      end
   until event =="char" and p1=="x"
--Respond
   if input == "Respond" then
      term.clear()
      term.setCursorPos(1,1)
      rednet.send(p1, input)
   end
else
   print("Turn on your WiFi")
end
Andybish #8
Posted 29 August 2012 - 06:48 PM
i think the problem might be that every time the program runs, wifi is set to false, so you have to input TurnOnWiFi for anything else to happen, even if the modem is already on.