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

I am having trouble with a part of my os system

Started by wolfcraft12, 07 January 2013 - 09:53 AM
wolfcraft12 #1
Posted 07 January 2013 - 10:53 AM
Ok so when I click on my section for games is give me an error I have spent atleast 2 hours trying to resolve it here is the code for it.

Please Help!!!


–Functions–

local w,h = term.getSize()
local select = 1
———————————

local function printCentered(str, ypos)
term.setCursorPos(w/2 - #str/2, ypos)
term.write(str)
end

local function printRight(str, ypos)
term.setCursorPos(w - #str, ypos)
term.write(str)
end

function drawHeader()
printCentered("AJ's Computer", 1)
printCentered(string.rep("|^|",w), 2)
printRight("By AJ Drew", h)
end



—–Menu Games——
term.clear()
function drawGame()
function drawHeader()
printCentered("Worm", 8)
printCentered("Rpg", 12)
printCentered("Quit", 16)

local ypos = 9
if select == 2 then ypos = 13
elseif select == 3 then ypos = h-1 end
printCentered("<><><><><><>", ypos)
end

————menu2————

local menustate = "game"

local mopt = {
["game"] = {
options = {"rpg", "worm", "quit"}
}
}


——RunMenu2Function——–

function runGame()
while true do
term.clear()
function drawGame()

local id, key = os.pullEvent("key")
–Note– up=200 down=208 enter=28

if key == 200 and select > 1 then select = select-1
elseif key == 208 and select < #mopt[menustate].options then select = select+1
elseif key == 28 then
if mopt[menustate].options[select] == "quit" then shell.run("desktop")
menustate = mopt[menustate].options[select]
elseif mopt[menustate].options[select] == "worm" then term.clear() shell.run("worm")
menustate = mopt[menustate].options[select]
elseif mopt[menustate].options[select] == "rpg" then term.clear() shell.run("rpg")
menustate = mopt[menustate].options[select]
end
end
end
end
end
end

runGame()
Orwell #2
Posted 07 January 2013 - 10:55 AM
Would you mind sharing the error with us then? :P/> It makes things easier >.< (yes, the error messages have a function..)
wolfcraft12 #3
Posted 07 January 2013 - 10:55 AM
Too long without yeilding
wolfcraft12 #4
Posted 07 January 2013 - 10:57 AM
if want to look at it for your self i can give you the ip to my server
PixelToast #5
Posted 07 January 2013 - 11:10 AM
because you are not running drawgame(), wich yeilds inside of the while loop'
declare drawgame before while true do and run it after
wolfcraft12 #6
Posted 07 January 2013 - 11:23 AM
ok so i changed it is still screwing with the same error


function runGame()
while true do
term.clear()
function drawGame()
function drawHeader()
Orwell #7
Posted 07 January 2013 - 11:28 AM
Do you know that this doesn't run the function?

function drawGame()
It's just the beginning of the definition of the function. You need to put that outside of runGame function and call it from with that function like this:

drawGame()

You have that problem because basically, what you do, is:

function runGame()
  while true do
    term.clear()
    -- defines function drawGame -> doesn't run it!
    -- defines function drawHeader -> doesn't run it!
  end
end
You define the function, but you don't call them. So this is just a loop of clearing. It doesn't yield ever (functions like sleep() and os.pullEvent() do yield), so it gets interrupted after 10 seconds with that error.
wolfcraft12 #8
Posted 07 January 2013 - 11:36 AM
Thank you so much that helped a bunch!