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

Error HALP

Started by Dapperwbs, 11 March 2018 - 05:37 PM
Dapperwbs #1
Posted 11 March 2018 - 06:37 PM
i need help regarding this error "window:140: bios:80: bad argument: string expected,got nil"
Help appriciated!

-Dapperwbs
Lyqyd #2
Posted 11 March 2018 - 06:48 PM
Let's see the code you're running that produces the error, please.
Dapperwbs #3
Posted 11 March 2018 - 06:49 PM
how to i copy and paste it in? where would it be stored in the files of the mod?
cause ya know you cant copy paste stuff mid game…
Edited on 12 March 2018 - 11:43 AM
Lupus590 #4
Posted 11 March 2018 - 06:56 PM
also, you may want to run your code through http://www.computercraft.info/forums2/index.php?/topic/27844-trace-simple-stack-traces-for-errors/
Dapperwbs #5
Posted 11 March 2018 - 07:10 PM
and if you can can you tell me how to copy paste things into the game?
Bomb Bloke #6
Posted 12 March 2018 - 01:49 AM
how to i copy and paste it in? where would it be stored in the files of the mod?

Your code isn't stored "in the files of the mod", it's stored in the save folder of your Minecraft world. Check the "computers" folder in there for a subfolder matching the id of the system you're working on.

If you don't have access to the world save (say because you're playing on an online server), you can use the pastebin script to upload your code straight to pastebin. Then you need only provide the link back here.

Of the top of my head, this error may be caused by your code setting an invalid text / background colour, and then later trying to output something to the display terminal.
Dapperwbs #7
Posted 12 March 2018 - 12:41 PM
thank you very much ill have it ready by tommorow. i cant today. i got stuff to do. sry
Dapperwbs #8
Posted 12 March 2018 - 01:09 PM
nvm i have enough time here ya go:

os = os.pullEventRaw()
m = peripheral.wrap("left")
m.setTextColor(1)
m.setTextScale(1)
local w,h = m.getSize()
function printCen(y,s)
  local x = math.floor((w - string.len(s)) /2)
  local xm = math.floor((51- string.len(s)) /2)
  m.setCursorPos(x,y)
  term.setCursorPos(xm,y)
  m.clearLine()
  term.clearLine()
  m.write(s)
  print(s)
end
printCen(1,"MACRO OSX")
m.setCursorPos(1,4)
m.write("Loading")
term.clear()
term.setCursorPos(1,1)
print("MACRO OSX")
print("Loading")
sleep(5)
term.setCursorPos(17,15)
textutils.slowPrint("..................")
m.setBackgroundColor(3)
sleep(3)
m.clear()
term.clear()
local option = 1
function numSel()
  local e,p = os
  if e == "key" then
    local key = p
    if key == 119 then
	  if option < 4 then
	    option = option + 1
	  end
    elseif key == 155 then
	  if option > 1 then
	    option = option - 1
	  end
    end
  end
end
function lineRemove()
  m.clearLine(math.floor(h/2))
  term.clearLine(math.floor(h/2))
  m.clearLine(math.floor(h/2) + 1)
  term.clearLine(math.floor(h/2) + 1)
  m.clearLine(math.floor(h/2) + 2)
  term.clearLine(math.floor(h/2) + 2)
  m.clearLine(math.floor(h/2) + 3)
  term.clearLine(math.floor(h/2) + 3)
end
printCen(1,"MACRO OSX Official")
sleep(2)
while true do
  numSel()
  lineRemove()
  if option == 1 then
    m.setTextColor(9)
    term.setTextColor(9)
    printCen(math.floor(h/2),"Command Promt")
    m.setTextColor(1)
    term.setTextColor(1)
    printCen(math.floor(h/2) + 1,"Programs")
    printCen(math.floor(h/2) + 2,"ShutDown")
    printCen(math.floor(h/2) + 3,"Uninstall")
  elseif option == 2 then
    printCen(math.floor(h/2),"Command Prompt")
    m.setTextColor(9)
    term.setTextColor(9)
    printCen(math.floor(h/2) + 1,"Programs")
    m.setTextColor(1)
    term.setTextColor(1)
    printCen(math.floor(h/2) + 2,"ShutDown")
    printCen(math.floor(h/2) + 3,"Uninstall")
  elseif option == 3 then
    printCen(math.floor(h/2),"Command Prompt")
    printCen(math.floor(h/2) + 1,"Programs")
    m.setTextColor(9)
    term.setTextColor(9)
    printCen(math.floor(h/2) + 2,"ShutDown")
    m.setTextColor(1)
    term.setTextColor(1)
    printCen(math.floor(h/2) + 3,"Uninstall")
  elseif option == 4 then
    printCen(math.floor(h/2),"Command Prompt")
    printCen(math.floor(h/2) + 1,"Programs")
    printCen(math.floor(h/2) + 2,"ShutDown")
    m.setTextColor(9)
    term.setTextColor(9)
    print(math.floor(h/2) + 3,"Uninstall")
    m.setTextColor(1)
    term.setTextColor(1)
  end
end
EveryOS #9
Posted 12 March 2018 - 01:23 PM
What version of CC?

Edit A:
Also wanted to point out:

print(math.floor(h/2) + 3,"Uninstall") --Edit D: should be printCen
I think that's a typo

Edit B:

m.setTextColor(9)
m.setBackgroundColor(3)
I thought only numbers that could be represented by 2^n, as well as 0, were valid? Maybe I'm wrong?

Edit C:
Anyways, if you know that your user does not have a resource pack, it's better to just use the colors or colours APIs

Edit E:
Just curious, can you try adding the following script to your code right after the declaration of var m?

do
  local nativeBlit = m.blit
  m.blit = function(a, b, c)
   term.setTextColor(colors.white)
   term.setBackgroundColor(colors.black)
   print("Blitting in 1s")
   sleep(1)
   if not pcall(nativeblit, a, b, c) then
	  term.setBackgroundColor(colors.black)
	  error("Blit error")
	end
	print("Blit success!")
end
And tell me the output
Edited on 12 March 2018 - 01:48 PM
Dapperwbs #10
Posted 12 March 2018 - 08:11 PM
so with the number thing do you just want me to make the number even or something? since its to the power of 2? im sry i have no idea what you mean :lol:/> . Btw your code didnt output anything :(/>
EveryOS #11
Posted 12 March 2018 - 08:21 PM

colors.white = 1
colors.orange = 2
colors.magenta = 4
colors.lightBlue = 8
colors.yellow = 16
colors.lime = 32
colors.pink = 64
colors.gray = 128
colors.lightGray = 256
colors.cyan = 512
colors.purple = 1024
colors.blue = 2048
colors.brown = 4096
colors.green = 8192
colors.red = 16384
colors.black = 32768
Using this color lookup, you can either type the number after the "=" or the word before the "="

EG

term.setTextColor(colors.orange) --This is orange
term.setTextColor(2) --This is also orange
KingofGamesYami #12
Posted 12 March 2018 - 08:58 PM
There is an awesome table of valid colors listed on the wiki page.
Dapperwbs #13
Posted 12 March 2018 - 11:30 PM
Thanks but my code still doesnt work can you please tell me if theres anything wrong with the numSel() function?



Btw thank you so much for the quick help
Edited on 12 March 2018 - 10:31 PM
SuperDyl19 #14
Posted 13 March 2018 - 02:35 AM
I think this page will help:

http://computercraft.info/wiki/Os.pullEvent

The os.pullevent() and os.pullEventRaw() are almost identical in usage so this page will help with both. os.pullEvent() can have a parameter added to it to make it only save values to os if the string shares the same name as the event. In this case, it'd be
os = os.pullEventRaw("key")

The problem with this is that the event "key" returns for os a string with the value "key" and drops the value of the number for the key pressed. So, a second variable needs to be added making the code now this:

os, key = os.pullEventRaw("key")

Key works as you wanted p to later in the code.

Now let's look at the function. First off, as we already have the values for the conditional tests (==) and we don't change the values within the function, the function doesn't need any local variables added. Instead, remove both of these lines:

local e, p = os
local key = p

The conditional tests can then be solved by just changing 'e' to "os". This uses the variables from the beginning to avoid redundancy and fixes the conditional issues. If you're curious, the problems were that 'p' didn't receive a value from "os" and "key" recieved its value from 'p', which had no value (meaning nil).

Last thing is this: you can make your code easier to edit for testing keyboard clicks using this handy chart http://computercraft.info/wiki/Key_(event) and the keys.getName() function found here: http://computercraft.info/wiki/Keys.getName .
A list of key names used by computercraft can be found here: http://computercraft.info/wiki/Keys_(API) . This will make it easier to add and change available keys that your program tests for.

I hope this helps!
EveryOS #15
Posted 13 March 2018 - 05:18 PM
Try this code
Code

os.pullEvent = os.pullEventRaw
local function fWrapTerm(tOldTerm)
	local tMyTerm = {}
	for k, v in pairs(tOldTerm) do tMyTerm[k]=function(...)return v(table.unpack({...})) end end
	tMyTerm.write = function(tText, bCentered)
		if bCentered~=false then
			local nX, nY = tOldTerm.getCursorPos()
			local nL, nH = tOldTerm.getSize()
			tOldTerm.setCursorPos(math.floor(nL/2-#tText/2), nY)
		end
		tOldTerm.write(tText)
	end
	tMyTerm.current = function()
	  return tMyTerm
	end
	return tMyTerm
end
local tMon = peripheral.wrap("left") or peripheral.find("monitor") or term.current() or error("NO MONITORS FOUND")
local tWrappedTerm = fWrapTerm(term.current())
local tWrappedMon = fWrapTerm(tMon)
local function fGeneralWrite(tText, bIsCentered)
	tWrappedTerm.write(tText, bIsCentered)
	tWrappedMon.write(tText, bIsCentered)
end
local function fResetTerm(term)
	term.setBackgroundColor(colors.black)
	term.setTextColor(colors.white)
	term.clear()
	term.setCursorPos(1, 1)
	term.setCursorBlink(false)
end
local function fMenu(sHead, tMenu, tColors, tTerm)
	fResetTerm(tTerm)
	local tOldTerm = term.current()
	term.redirect(tTerm)
	local nL, nH = tTerm.getSize()
	local nDown = 1
	tTerm.setTextColor((tTerm.isColor() and colors.green) or colors.white)
	if sHead then nDown = 2 + write(sHead) end
	term.redirect(window.create(term.current(), 1, nDown, nL, nH-nDown+1, true))
	nL, nH = term.getSize()
	local nMinShow, nItem = 1, 1
	while true do
		term.clear()
		term.setCursorPos(1, 1)
		if nMinShow>nItem then nMinShow = nItem end
		if (nMinShow+nH-2)<nItem then nMinShow = nMinShow+1 end
		if (nItem == #tMenu) and nH < #tMenu then nMinShow = nItem-nH+1 end
		for nI = nMinShow, nMinShow + nH-2 do
			if tColors then term.setTextColor(tColors[nI] or colors.white) end
			if nI == nItem then
				term.setTextColor(colors.gray)
				write(tMenu[nI])
				if not (nI == #tMenu) then print() end
			else
				print(tMenu[nI] or "")
			end
		end
		if nMinShow + (nH - 1) < #tMenu then
			term.setCursorPos(1, nH)
			term.setTextColor(colors.white)
			term.write("[MORE OPTIONS BELOW]")
		elseif nMinShow + (nH - 1) == #tMenu then
			term.setCursorPos(1, nH)
			if nItem == #tMenu then
				term.setTextColor(colors.gray)
				term.write(tMenu[#tMenu])
			else
				if tColors then term.setTextColor(tColors[#tMenu] or colors.white) end
				term.write(tMenu[#tMenu])
			end
		end
		term.setTextColor(colors.white)
		local tEvent = {os.pullEvent("key")}
		if (tEvent[2] == keys.down) and (nItem < #tMenu) then nItem = nItem + 1 end
		if (tEvent[2] == keys.up) and (nItem > 1) then nItem = nItem - 1 end
		if (tEvent[2] == keys.enter) then term.redirect(tOldTerm) return nItem end
		os.queueEvent(os.pullEvent())
	end
end
fResetTerm(term)
fResetTerm(tMon)
tMon.setTextScale(1)
tWrappedMon.write("MACRO OSX")
term.write("MACRO OSX\nLoading")
term.setCursorPos(17,15)
textutils.slowPrint("..................")
sleep(3)
fResetTerm(term)
fResetTerm(tMon)
fGeneralWrite("MACRO OSX Official")
sleep(2)
local opt
local function wrapMenu(myterm)
  return function() opt = fMenu("MACRO OSX Official command prompt", {"Programs", "Power", "Uninstall"}, {nil, nil, colors.red}, myterm) end
end
parallel.waitForAny(wrapMenu(tWrappedTerm), wrapMenu(tWrappedMon))
if opt == 1 then
--Do something
elseif opt ==2 then
--Do something
elsif opt == 3 then
--Do something
end
Last I checked it worked except that the menu would only change selection on the monitor and text was not centered, but I made a few edits since so it may work better or worse.
Edited on 13 March 2018 - 04:19 PM
Dapperwbs #16
Posted 13 March 2018 - 07:40 PM
alright i altered my code and cant seem to find the error with my key input once again any help?

m = peripheral.wrap("left")
m.setTextColor(1)
m.setTextScale(1)
local w,h = m.getSize()
function printCen(y,s)
  local x = math.floor((w - string.len(s)) /2)
  local xm = math.floor((51- string.len(s)) /2)
  m.setCursorPos(x,y)
  term.setCursorPos(xm,y)
  m.clearLine()
  term.clearLine()
  m.write(s)
  print(s)
end
printCen(1,"MACRO OSX")
m.setCursorPos(1,4)
m.write("Loading")
term.clear()
term.setCursorPos(1,1)
print("MACRO OSX")
print("Loading")
sleep(2)
term.setCursorPos(17,15)
textutils.slowPrint("..................")
m.setBackgroundColor(2)
sleep(3)
m.clear()
term.clear()
local option = 1
printCen(1,"MACRO OSX Official")
function numSel()
  if e == "key" then
	if key == keys.w then
	  if option < 4 then
		option = option + 1
	  end
	elseif key == keys.s then
	  if option > 1 then
		option = option - 1
	  end
	end
  end
end
function lineRemove()
  m.clearLine(math.floor(h/2))
  term.clearLine(math.floor(h/2))
  m.clearLine(math.floor(h/2) + 1)
  term.clearLine(math.floor(h/2) + 1)
  m.clearLine(math.floor(h/2) + 2)
  term.clearLine(math.floor(h/2) + 2)
  m.clearLine(math.floor(h/2) + 3)
  term.clearLine(math.floor(h/2) + 3)
end
while true do
  sleep(0.05)
  local e,key = os.pullEvent("key")
  numSel()
  lineRemove()
  if option == 1 then
	m.setTextColor(4)
	term.setTextColor(4)
	printCen(math.floor(h/2),"Command Prompt")
	m.setTextColor(1)
	term.setTextColor(1)
	printCen(math.floor(h/2) + 1,"Programs")
	printCen(math.floor(h/2) + 2,"ShutDown")
	printCen(math.floor(h/2) + 3,"Uninstall")
  elseif option == 2 then
	printCen(math.floor(h/2),"Command Prompt")
	m.setTextColor(4)
	term.setTextColor(4)
	printCen(math.floor(h/2) + 1,"Programs")
	m.setTextColor(1)
	term.setTextColor(1)
	printCen(math.floor(h/2) + 2,"ShutDown")
	printCen(math.floor(h/2) + 3,"Uninstall")
  elseif option == 3 then
	printCen(math.floor(h/2),"Command Prompt")
	printCen(math.floor(h/2) + 1,"Programs")
	m.setTextColor(4)
	term.setTextColor(4)
	printCen(math.floor(h/2) + 2,"ShutDown")
	m.setTextColor(1)
	term.setTextColor(1)
	printCen(math.floor(h/2) + 3,"Uninstall")
  elseif option == 4 then
	printCen(math.floor(h/2),"Command Prompt")
	printCen(math.floor(h/2) + 1,"Programs")
	printCen(math.floor(h/2) + 2,"ShutDown")
	m.setTextColor(4)
	term.setTextColor(4)
	printCen(math.floor(h/2) + 3,"Uninstall")
	m.setTextColor(1)
	term.setTextColor(1)
  end
end
Edited on 13 March 2018 - 06:47 PM
EveryOS #17
Posted 13 March 2018 - 08:33 PM
Did you try the version I posted?
Dog #18
Posted 13 March 2018 - 08:39 PM
alright i altered my code and cant seem to find the error with my key input once again any help?

Your problem has to do with scope. Hopefully Bomb Bloke will poke his head in here and expand a bit for you (I'm terrible at explaining this stuff). Basically, your variables e and key are local to your while loop, so your numSel function can't see them. You can fix this easily enough by passing them to numSel and having numSel setup to make use of passed values - like so…

In your while loop, instead of just calling numSel(), you would call numSel(e, key)

When you declare your numSel function instead of using function numSel() use function numSel(e, key)

By making those changes, your selection function should work, or at least produce an error that'll lead to the next thing that need fixing.
Edited on 13 March 2018 - 07:41 PM
Dapperwbs #19
Posted 13 March 2018 - 08:45 PM
Thank you but just a question. why cant the numSel function see the local var if its in the same loop?
Sry im kinda a nub
Also the code didnt work did i input the arguments correctly?

m = peripheral.wrap("left")
m.setTextColor(1)
m.setTextScale(1)
local w,h = m.getSize()
function printCen(y,s)
  local x = math.floor((w - string.len(s)) /2)
  local xm = math.floor((51- string.len(s)) /2)
  m.setCursorPos(x,y)
  term.setCursorPos(xm,y)
  m.clearLine()
  term.clearLine()
  m.write(s)
  print(s)
end
printCen(1,"MACRO OSX")
m.setCursorPos(1,4)
m.write("Loading")
term.clear()
term.setCursorPos(1,1)
print("MACRO OSX")
print("Loading")
sleep(2)
term.setCursorPos(17,15)
textutils.slowPrint("..................")
m.setBackgroundColor(2)
sleep(3)
m.clear()
term.clear()
local option = 1
printCen(1,"MACRO OSX Official")
function numSel()
  if e == "key" then
	if key == keys.w then
	  if option < 4 then
		option = option + 1
	  end
	elseif key == keys.s then
	  if option > 1 then
		option = option - 1
	  end
	end
  end
end
function lineRemove()
  m.clearLine(math.floor(h/2))
  term.clearLine(math.floor(h/2))
  m.clearLine(math.floor(h/2) + 1)
  term.clearLine(math.floor(h/2) + 1)
  m.clearLine(math.floor(h/2) + 2)
  term.clearLine(math.floor(h/2) + 2)
  m.clearLine(math.floor(h/2) + 3)
  term.clearLine(math.floor(h/2) + 3)
end
while true do
  sleep(0.05)
  local e,key = os.pullEvent("key")
  numSel(e, key)
  lineRemove()
  if option == 1 then
	m.setTextColor(4)
	term.setTextColor(4)
	printCen(math.floor(h/2),"Command Prompt")
	m.setTextColor(1)
	term.setTextColor(1)
	printCen(math.floor(h/2) + 1,"Programs")
	printCen(math.floor(h/2) + 2,"ShutDown")
	printCen(math.floor(h/2) + 3,"Uninstall")
  elseif option == 2 then
	printCen(math.floor(h/2),"Command Prompt")
	m.setTextColor(4)
	term.setTextColor(4)
	printCen(math.floor(h/2) + 1,"Programs")
	m.setTextColor(1)
	term.setTextColor(1)
	printCen(math.floor(h/2) + 2,"ShutDown")
	printCen(math.floor(h/2) + 3,"Uninstall")
  elseif option == 3 then
	printCen(math.floor(h/2),"Command Prompt")
	printCen(math.floor(h/2) + 1,"Programs")
	m.setTextColor(4)
	term.setTextColor(4)
	printCen(math.floor(h/2) + 2,"ShutDown")
	m.setTextColor(1)
	term.setTextColor(1)
	printCen(math.floor(h/2) + 3,"Uninstall")
  elseif option == 4 then
	printCen(math.floor(h/2),"Command Prompt")
	printCen(math.floor(h/2) + 1,"Programs")
	printCen(math.floor(h/2) + 2,"ShutDown")
	m.setTextColor(4)
	term.setTextColor(4)
	printCen(math.floor(h/2) + 3,"Uninstall")
	m.setTextColor(1)
	term.setTextColor(1)
  end
end
nvm i got it THANK YOU SO MUCH guys for the help
i will keep working on it and see you if im ready for more tips you guys are so helpful
THANK YOU again
Edited on 13 March 2018 - 07:52 PM
Dapperwbs #20
Posted 13 March 2018 - 09:06 PM
oh hang on i got an error sry if i do

function numSel(e,key)
  if e == "key" then
    if key == keys.w then
	  if option < 4 then
	    option = option + 1
	  end
    elseif key == keys.s then
	  if option > 1 then
	    option = option - 1
	  end
    end
  end
end
it works but if i swap the + and -

function numSel(e,key)
  if e == "key" then
    if key == keys.w then
	  if option < 4 then
	    option = option - 1
	  end
    elseif key == keys.s then
	  if option > 1 then
	    option = option + 1
	  end
    end
  end
end
it doesnt work any help?
Dog #21
Posted 13 March 2018 - 09:29 PM
what's the error you received?
EveryOS #22
Posted 13 March 2018 - 10:03 PM
Hey so I just retested the code I made earlier. I fixed a compile time error and then some run time bugs.
Can you try this code:

os.pullEvent = os.pullEventRaw
local function fWrapTerm(tOldTerm)
	    local tMyTerm = {}
	    for k, v in pairs(tOldTerm) do tMyTerm[k]=function(...)return v(table.unpack({...})) end end
	    tMyTerm.write = function(tText, bCentered)
			    if bCentered~=false then
					    local nX, nY = tOldTerm.getCursorPos()
					    local nL, nH = tOldTerm.getSize()
					    tOldTerm.setCursorPos(math.floor(nL/2-#tText/2), nY)
			    end
			    tOldTerm.write(tText)
	    end
	    return tMyTerm
end
local tMon = peripheral.wrap("left") or peripheral.find("monitor") or term.current() or error("NO MONITORS FOUND")
local tWrappedTerm = fWrapTerm(term.current())
local tWrappedMon = fWrapTerm(tMon)
local function fGeneralWrite(tText, bIsCentered)
	    tWrappedTerm.write(tText, bIsCentered)
	    tWrappedMon.write(tText, bIsCentered)
end
local function fResetTerm(term)
	    term.setBackgroundColor(colors.black)
	    term.setTextColor(colors.white)
	    term.clear()
	    term.setCursorPos(1, 1)
	    term.setCursorBlink(false)
end
local cacheE = {""}
local function fMenu(sHead, tMenu, tColors, tTerm)
	    fResetTerm(tTerm)
	    local tOldTerm = term.current()
	    term.redirect(tTerm)
	    local nL, nH = tTerm.getSize()
	    local nDown = 1
	    tTerm.setTextColor((tTerm.isColor() and colors.green) or colors.white)
	    term.setCursorPos(math.floor(nL/2-#sHead/2), 1)
	    if sHead then nDown = 2 + write(sHead) end
	    nL, nH = term.getSize()
	    local nMinShow, nItem = 1, 1
	    local tMyWindow = fWrapTerm(window.create(term.current(), 1, nDown, nL, nH-nDown+1, true))
	    while true do
			    term.redirect(tMyWindow)
			    term.clear()
			    term.setCursorPos(1, 1)
			    if nMinShow>nItem then nMinShow = nItem end
			    if (nMinShow+nH-2)<nItem then nMinShow = nMinShow+1 end
			    if (nItem == #tMenu) and nH < #tMenu then nMinShow = nItem-nH+1 end
			    for nI = nMinShow, nMinShow + nH-2 do
					    if tColors then term.setTextColor(tColors[nI] or colors.white) end
					    if nI == nItem then
							    term.setTextColor(colors.gray)
							    if tMenu[nI] then
									    write(tMenu[nI])
							    end
							    if not (nI == #tMenu) then print() end
					    else
							    if tMenu[nI] then
									    print(tMenu[nI])
							    end
					    end
			    end
			    if nMinShow + (nH - 1) < #tMenu then
					    term.setCursorPos(1, nH)
					    term.setTextColor(colors.white)
					    term.write("[MORE OPTIONS BELOW]")
			    elseif nMinShow + (nH - 1) == #tMenu then
					    term.setCursorPos(1, nH)
					    if nItem == #tMenu then
							    term.setTextColor(colors.gray)
							    term.write(tMenu[#tMenu])
					    else
							    if tColors then term.setTextColor(tColors[#tMenu] or colors.white) end
							    term.write(tMenu[#tMenu])
					    end
			    end
			    term.setTextColor(colors.white)
			    local tEvent = {os.pullEvent("key")}
			    if (tEvent[2] == keys.down) and (nItem < #tMenu) then nItem = nItem + 1 end
			    if (tEvent[2] == keys.up) and (nItem > 1) then nItem = nItem - 1 end
			    if (tEvent[2] == keys.enter) then term.redirect(tOldTerm) return nItem end
	    end
end
fResetTerm(term)
fResetTerm(tMon)
tMon.setTextScale(1)
tWrappedMon.write("MACRO OSX")
term.write("MACRO OSX\nLoading")
term.setCursorPos(17,15)
textutils.slowPrint("..................")
sleep(3)
fResetTerm(term)
fResetTerm(tMon)
fGeneralWrite("MACRO OSX Official")
sleep(2)
local opt
local function wrapMenu(myterm)
	    return function() opt = fMenu("Command Prompt", {"Programs", "Power", "Uninstall"}, {nil, nil, colors.red}, myterm) end
end
parallel.waitForAny(wrapMenu(term.current()), wrapMenu(tMon))
if opt == 1 then
	    --Do something
elseif opt ==2 then
	    --Do something
elseif opt == 3 then
	    --Do something
end

It should be easier to edit and also completely work.