Jump to content




Dodgy os.pullEvent AGAIN >:O

help

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

#1 Mendax

  • Members
  • 366 posts

Posted 16 November 2012 - 04:21 AM

My OS.pullEvent script is acting up again, could someone correct it for me?
ver = "1.0"

function ftphost(fpath,finputid)
rednet.send(finputid,"SKS-UPLOAD")
sleep(0.5)
file = fs.open(path,"r")
content = file.readAll()
rednet.send(inputid,(content))
file.close()
end
function ftpclient(fpath,finputid)
rednet.send(finputid,"SKS-DOWNLOAD")
sleep(0.5)
file = fs.open(path,"w")
id, msg = rednet.receive()
if id == inputid then
file.write((msg))
file.close()
end
end

term.clear()
term.setCursorPos(1,1)
print(" ** SKS-OS v"..ver.." ** ")
while true do
write "$> "
local command = read()
if command == "LOAD" then
print "LOAD FROM:"
local loadname = read()
print "LOADING"
if fs.exists("/sksRAM") then fs.delete("/sksRAM") end
if fs.exists("disk/"..loadname) then
fs.copy("disk/"..loadname,"/sksRAM")
print "LOADED"
else
print "404 - FELINE NOT FOUND"
end
elseif command == "SAVE" then
print "FILENAME:"
local savename = read()
if fs.exists("disk/"..savename) then fs.delete("disk/"..savename) end
if fs.exists("/sksRAM") then fs.copy("/sksRAM","disk/"..savename) end
elseif command == "RUN" then
if fs.exists("/sksRAM") then shell.run("/sksRAM") end
elseif command == "EDIT" then
shell.run("edit","sksRAM")
elseif command == "REDSET" then
print "ID:"
id = tonumber(read())
print "VALUE:"
value = read()
rednet.send(id,textutils.serialize({"SKS-REDSET",value}))
elseif command == "FTP" then
print "SEND OR RECEIVE? S/R"
event, char = os.pullEvent()
if char == "s" then
print "ID TO SEND TO:"
id = read()
ftphost("sksRAM",id)
elseif char == "r" then
print "ID TO RECEIVE FROM:"
id = read()
ftpclient("sksRAM",id)
end
end
end
it is this peice of code here:
event, char = os.pullEvent()


#2 faubiguy

  • Members
  • 213 posts

Posted 16 November 2012 - 04:34 AM

try:
repeat event, char = os.pullEvent("char")
until char:lower() == "s" or char:lower() == "r"


#3 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 16 November 2012 - 06:26 AM

You didn't specify which event it must pull. So os.pullEvent("char") is correct as faubiguy said.

Try this:
done = false
repeat
    event, char = os.pullEvent("char")
    if char == "s" then
        print "ID TO SEND TO:"
        id = read()
        ftphost("sksRAM",id)
        done = not done
    elseif char == "r" then
        print "ID TO RECEIVE FROM:"
        id = read()
        ftpclient("sksRAM",id)
        done = not done
    end
until done

Or simply like faubiguy said, but why lower the char?

repeat event, char = os.pullEvent("char") until char == "s" or char == "r"

if char == "s" then
    print "ID TO SEND TO:"
    id = read()
    ftphost("sksRAM",id)
elseif char == "r" then
    print "ID TO RECEIVE FROM:"
    id = read()
    ftpclient("sksRAM",id)
end


#4 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 16 November 2012 - 06:48 AM

Maybe in case you have Caps Lock on, or holding shift? I suppose, in this case, you'd better use the 'key' event, but it hardly matters.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users