the updater() function (in desktop) doesn't load the actual updater
passwordSetup() is also not working, like updater()
Because of pingPastebin(). It sends an HTTP request, then checks the first event in the event queue. Odds are that'll be a timer event from the sleep() call you're making in your drawDesktop() function, so "internet" gets set to false and not much else happens. Don't set "requesting" to false until you're sure you've got the event you want.
If you're really quick off the mark you can get in before the timer event as the code is, but that'll crash because the updater script attempts to call resetScreen(). This function is defined in the global scope by your desktop script, but APIs don't have access to
that scope; only to _G. All "user-mode scripts" use a different table for their global scope, so if you want to use functions across multiple scripts, best to load them up as
proper APIs.
going back in the uninstaller menu simply breaks rather than going back (tried various things - still can't get all of the desktop to display again and drawDesktop() freezes button selection)
Obviously you need to re-run the code that draws the desktop if you want the desktop to appear again, but currently, calling the drawDesktop() function involves starting a loop that repeats so long as disptime ~= 0, so it's not much good for simply drawing the desktop! I suggest you make a separate function for updating the time display.
Any other all-round tips are always appreciated; after all, one only succeeds at getting better at something if they practice and listen to advice.
Use the
keys API, it's filled with lots of lovely constants to make your script more readable! For example, this:
if b==2 then uCYes()
… becomes this:
if b==keys.one then uCYes()
Rather than having a ton of duplicate cases in your runDesktop() function, how about using "or":
if (event=="key" and sel==0 and b==2) or (event=="mouse_click" and b==1 and x>=2 and x<=8 and y==1) then sel=1
rDMenu()
Personally, I've taken to relying on these two functions:
-- Returns whether a click was performed at a given location.
-- If one parameter is passed, it checks to see if y is [1].
-- If two parameters are passed, it checks to see if x is [1] and y is [2].
-- If three parameters are passed, it checks to see if x is between [1]/[2] (non-inclusive) and y is [3].
-- If four paramaters are passed, it checks to see if x is between [1]/[2] and y is between [3]/[4] (non-inclusive).
local function clickedAt(...)
if myEvent[1] ~= "mouse_click" then return false end
if #arg == 1 then return (arg[1] == myEvent[4])
elseif #arg == 2 then return (myEvent[3] == arg[1] and myEvent[4] == arg[2])
elseif #arg == 3 then return (myEvent[3] > arg[1] and myEvent[3] < arg[2] and myEvent[4] == arg[3])
else return (myEvent[3] > arg[1] and myEvent[3] < arg[2] and myEvent[4] > arg[3] and myEvent[4] < arg[4]) end
end
-- Returns whether one of a given set of keys was pressed.
local function pressedKey(...)
if myEvent[1] ~= "key" then return false end
for i=1,#arg do if arg[i] == myEvent[2] then return true end end
return false
end
With myEvent localised to the whole script, and populated as a table:
myEvent = {os.pullEvent()}
… I can then do compact checks like so:
if (pressedKey(keys.one, keys.numPad1) and sel==0) or clickedAt(1, 9, 1) then sel=1
rDMenu()
The ternary technique
discussed here lets you turn this sort of thing:
if term.isColor() then term.write("(Use mouse & keyboard for selecting.)")
else term.write("(Use keyboard for selecting.)")
end
… into this sort of thing:
term.write("(Use " .. (term.isColor() and "mouse & " or "") .. "keyboard for selecting.)")