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

Dodgy os.pullEvent AGAIN >:O

Started by Mendax, 16 November 2012 - 03:21 AM
Mendax #1
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()
faubiguy #2
Posted 16 November 2012 - 04:34 AM
try:
repeat event, char = os.pullEvent("char")
until char:lower() == "s" or char:lower() == "r"
remiX #3
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
Orwell #4
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.