0 Members and 2 Guests are viewing this topic.
print("Chess timer starting...")--function variableslocal drawRectFill = zmg.drawRectFilllocal fastCopy = zmg.fastCopylocal makeColor = zmg.makeColorlocal drawPoint = zmg.drawPointlocal keyMenuFast = zmg.keyMenuFastlocal clear = zmg.clearlocal drawText = zmg.drawTextlocal keyDirectPoll = zmg.keyDirectPolllocal keyDirect = zmg.keyDirectlocal floor = math.floorlocal random = math.randomlocal time = zmg.timelocal ticks = zmg.ticks--screen varslocal SCREEN_WIDTH = 384local SCREEN_HEIGHT = 216local exit = 0--game variableslocal key = {F1=79, F2=69, F3=59, F4=49, F5=39, F6=29, Alpha=77, Exit=47, Optn=68, Up=28, Down=37, Left=38, Right=27, EXE=31}local chesstimer = {timerStart=60, add=0, turn="White", turnNum=1}local color = {bg=makeColor("white"), fg=makeColor("black")}local continue = 0local intro = 1local buffer = 0local timers = {white=chesstimer.timerStart, black=chesstimer.timerStart}local start=0--first poll and first start timerkeyDirectPoll()local startTime = ticks()--functionslocal function timeElapsed() return floor((ticks()-startTime)/100)endlocal function wait(timeToWait) local start = timeElapsed() while timeElapsed() - start < timeToWait do endendlocal function waitForKey(key) while keyDirect(key) == 0 do keyDirectPoll() endendlocal function toggleTurn() if chesstimer.turn == "White" then chesstimer.turn = "Black" chesstimer.turnNum = 2 else chesstimer.turn = "White" chesstimer.turnNum = 1 end start = timeElapsed()endlocal function introScreen() continue = 0 drawText(1, 1, "WAIT...", color.fg, color.bg) fastCopy() wait(3) drawText(1, 1, "Press [EXE] to continue", color.fg, color.bg) fastCopy() waitForKey(key.EXE) intro = 0endlocal function chessTimerScreen() start = timeElapsed() while exit ~= 1 do if keyDirect(key.Exit) > 0 then exit = 1 elseif keyDirect(key.F1) > 0 then toggleTurn() end --drawing drawText(1, SCREEN_HEIGHT - 10, "Next Player", color.fg, color.bg) drawText(1, 1, "Turn: " .. chesstimer.turn, color.fg, color.bg) drawText(1, 10, "White: " .. timers.white, color.fg, color.bg) drawText(1, 20, "Black: " .. timers.black, color.bg, color.fg) --math timeElapsedSinceTurn = timeElapsed - start timers[chesstimer.turnNum] = chesstimer.timerStart - timeElapsedSinceTurn keyDirectPoll() end exit=0 intro=1end--main loopwhile exit~=1 do clear() --intro screen if intro == 1 then fastCopy() introScreen() end --wait screen drawText(1, 1, "Press F1 when ready", color.fg, color.bg) drawText(1, SCREEN_HEIGHT - 10, "Next Player", color.fg, color.bg) --wait waitForKey(key.F1) --chesstimer screen chessTimerScreen() --refresh screen fastCopy() --keypoll keyDirectPoll()endprint("done.")print("")
"welcome to the world of computers, where everything seems to be based on random number generators"
if you put code after "drawText(1, 1, "Press [EXE] to continue", color.fg, color.bg)", like another drawText, does it get executed ?Also, is line 95 intentional ?
print("Chess timer starting...")--function variableslocal drawRectFill = zmg.drawRectFilllocal fastCopy = zmg.fastCopylocal makeColor = zmg.makeColorlocal drawPoint = zmg.drawPointlocal keyMenuFast = zmg.keyMenuFastlocal clear = zmg.clearlocal drawText = zmg.drawTextlocal keyDirectPoll = zmg.keyDirectPolllocal keyDirect = zmg.keyDirectlocal floor = math.floorlocal random = math.randomlocal time = zmg.timelocal ticks = zmg.ticks--screen varslocal SCREEN_WIDTH = 384local SCREEN_HEIGHT = 216local exit = 0--game variableslocal key = {F1=79, F2=69, F3=59, F4=49, F5=39, F6=29, Alpha=77, Exit=47, Optn=68, Up=28, Down=37, Left=38, Right=27, EXE=31}local chesstimer = {timerStart=60, add=0, turn="White", turnNum=1}local color = {bg=makeColor("white"), fg=makeColor("black"), dbfg=makeColor("red"), dbbg=makeColor("black")}local continue = 0local intro = 1local buffer = 0local timers = {}local start=0local timeElapsedSinceTurn = 0--first poll and first start timerkeyDirectPoll()local startTime = ticks()--functionslocal function timeElapsed() return floor((ticks()-startTime)/128)endlocal function convertTime(t, format) min = floor(t/60) sec = t-(min*60) if format=="m" then return min elseif format=="s" then return sec endendlocal function wait(timeToWait) local start = timeElapsed() while timeElapsed() - start < timeToWait do endendlocal function waitForKey(key) while keyDirect(key) == 0 do keyDirectPoll() endendlocal function toggleTurn() fastCopy() timers[chesstimer.turnNum + 2] = (timers[chesstimer.turnNum + 2] - timeElapsedSinceTurn) + chesstimer.add if chesstimer.turn == "White" then chesstimer.turn = "Black" chesstimer.turnNum = 2 else chesstimer.turn = "White" chesstimer.turnNum = 1 end start = timeElapsed()endlocal function outOfTime(message) clear() drawText(floor(SCREEN_WIDTH/2),floor(SCREEN_HEIGHT/2),message,makeColor("black"), makeColor("red")) fastCopy() waitForKey(key.Exit)endlocal function introScreen() clear() continue = 0 drawText(1, 1, "WAIT...", color.fg, color.bg) fastCopy() min = 1 wait(1) while continue==0 do clear() keyDirectPoll() if keyDirect(key.Up)>0 and min<15 then while keyDirect(key.Up) > 0 do keyDirectPoll() end min = min+1 elseif keyDirect(key.Down)>0 and min>0 then while keyDirect(key.Down) > 0 do keyDirectPoll() end min = min-1 end if keyDirect(key.EXE)>0 then continue = 1 end drawText(1, 1, "Press [EXE] to continue", color.fg, color.bg) drawText(1, 20, "minutes: " .. min, color.fg, color.bg) fastCopy() end chesstimer.timerStart = min*60 timers[1] = chesstimer.timerStart timers[2] = chesstimer.timerStart timers[3] = chesstimer.timerStart timers[4] = chesstimer.timerStart intro = 0endlocal function chessTimerScreen() clear() start = timeElapsed() while exit ~= 1 do clear() if keyDirect(key.Exit) > 0 then exit = 1 elseif keyDirect(key.F1) > 0 then while keyDirect(key.F1) > 0 do keyDirectPoll() end toggleTurn() end --drawing drawText(1, SCREEN_HEIGHT - 20, "Next Player", color.fg, color.bg) drawText(1, 1, "Turn: " .. chesstimer.turn, color.fg, color.bg) drawText(1, 20, "White: " .. convertTime(timers[1],"m") .. ":" .. convertTime(timers[1],"s"), color.fg, color.bg) drawText(1, 40, "Black: " .. convertTime(timers[2],"m") .. ":" .. convertTime(timers[2],"s"), color.bg, color.fg) fastCopy() --math timeElapsedSinceTurn = timeElapsed() - start timers[chesstimer.turnNum] = timers[chesstimer.turnNum + 2] - timeElapsedSinceTurn if timers[chesstimer.turnNum] < 0 then outOfTime(chesstimer.turn .. " ran out of time!") end --[[-- debug drawText(1, 70, "DEBUG: " .. timers[1], color.dbfg, color.dbbg) --]]-- keyDirectPoll() endend--main loopwhile exit~=1 do clear() --intro screen if intro == 1 then fastCopy() introScreen() end --wait screen clear() drawText(1, 1, "Press F1 when ready", color.fg, color.bg) drawText(1, SCREEN_HEIGHT - 20, "Next Player", color.fg, color.bg) fastCopy() --wait waitForKey(key.F1) --chesstimer screen chessTimerScreen() --refresh screen fastCopy() --keypoll keyDirectPoll()endprint("done.")print("")
...Also, I noticed you have--[[-- and --]]--If you simply want to uncomment a block of code, just change the --[[ into ---[[. That's all that's required, and you can comment it as easy later
print("Chess timer starting...")--function variableslocal drawRectFill = zmg.drawRectFilllocal fastCopy = zmg.fastCopylocal makeColor = zmg.makeColorlocal drawPoint = zmg.drawPointlocal keyMenuFast = zmg.keyMenuFastlocal clear = zmg.clearlocal drawText = zmg.drawTextlocal keyDirectPoll = zmg.keyDirectPolllocal keyDirect = zmg.keyDirectlocal floor = math.floorlocal random = math.randomlocal time = zmg.timelocal ticks = zmg.ticks--screen varslocal SCREEN_WIDTH = 384local SCREEN_HEIGHT = 216local exit = 0--game variableslocal key = {F1=79, F2=69, F3=59, F4=49, F5=39, F6=29, Alpha=77, Exit=47, Optn=68, Up=28, Down=37, Left=38, Right=27, EXE=31}local chesstimer = {timerStart=60, add=0, turn="White", turnNum=1}local color = {bg=makeColor("white"), fg=makeColor("black"), dbfg=makeColor("red"), dbbg=makeColor("black")}local continue = 0local intro = 1local buffer = 0local timers = {}local start=0local timeElapsedSinceTurn = 0--first poll and first start timerkeyDirectPoll()local startTime = ticks()--functionslocal function timeElapsed() return floor((ticks()-startTime)/128)endlocal function convertTime(t, format) min = floor(t/60) sec = t-(min*60) if format=="m" then return min elseif format=="s" then return sec endendlocal function wait(timeToWait) local start = timeElapsed() while timeElapsed() - start < timeToWait do endendlocal function waitForKey(key) while keyDirect(key) == 0 do keyDirectPoll() endendlocal function toggleTurn() fastCopy() timers[chesstimer.turnNum + 2] = (timers[chesstimer.turnNum + 2] - timeElapsedSinceTurn) + chesstimer.add if chesstimer.turn == "White" then chesstimer.turn = "Black" chesstimer.turnNum = 2 else chesstimer.turn = "White" chesstimer.turnNum = 1 end start = timeElapsed()end--[[--local function outOfTime(message) clear() drawText(floor(SCREEN_WIDTH/2),floor(SCREEN_HEIGHT/2),message,makeColor("black"), makeColor("red")) fastCopy() waitForKey(key.Exit)end--]]--local function introScreen() clear() continue = 0 drawText(1, 1, "WAIT...", color.fg, color.bg) fastCopy() min = 1 wait(1) while continue==0 do clear() keyDirectPoll() if keyDirect(key.Up)>0 and min<15 then while keyDirect(key.Up) > 0 do keyDirectPoll() end min = min+1 elseif keyDirect(key.Down)>0 and min>0 then while keyDirect(key.Down) > 0 do keyDirectPoll() end min = min-1 end if keyDirect(key.EXE)>0 then continue = 1 end drawText(1, 1, "Press [EXE] to continue", color.fg, color.bg) drawText(1, 20, "minutes: " .. min, color.fg, color.bg) fastCopy() end chesstimer.timerStart = min*60 timers[1] = chesstimer.timerStart timers[2] = chesstimer.timerStart timers[3] = chesstimer.timerStart timers[4] = chesstimer.timerStart intro = 0endlocal function chessTimerScreen() clear() start = timeElapsed() while exit ~= 1 do clear() if keyDirect(key.Exit) > 0 then exit = 1 elseif keyDirect(key.F1) > 0 then while keyDirect(key.F1) > 0 do keyDirectPoll() end toggleTurn() end --drawing drawText(1, SCREEN_HEIGHT - 20, "Next Player", color.fg, color.bg) drawText(1, 1, "Turn: " .. chesstimer.turn, color.fg, color.bg) drawText(1, 20, "White: " .. convertTime(timers[1],"m") .. ":" .. convertTime(timers[1],"s"), color.fg, color.bg) drawText(1, 40, "Black: " .. convertTime(timers[2],"m") .. ":" .. convertTime(timers[2],"s"), color.bg, color.fg) fastCopy() --math timeElapsedSinceTurn = timeElapsed() - start timers[chesstimer.turnNum] = timers[chesstimer.turnNum + 2] - timeElapsedSinceTurn if timers[chesstimer.turnNum] < 0 then clear() drawText(1,1,chesstimer.turn .. " ran out of time!",makeColor("black"), makeColor("red")) fastCopy() waitForKey(key.Exit) exit = 1 end --[[-- debug drawText(1, 70, "DEBUG: " .. timers[1], color.dbfg, color.dbbg) --]]-- keyDirectPoll() endend--main loopwhile exit~=1 do clear() --intro screen if intro == 1 then fastCopy() introScreen() end --wait screen clear() drawText(1, 1, "Press F1 when ready", color.fg, color.bg) drawText(1, SCREEN_HEIGHT - 20, "Next Player", color.fg, color.bg) fastCopy() --wait waitForKey(key.F1) --chesstimer screen chessTimerScreen() --refresh screen fastCopy() --keypoll keyDirectPoll()endprint("done.")print("")
print("Chess timer starting...")--function variableslocal drawRectFill = zmg.drawRectFilllocal drawRect = zmg.drawRectlocal fastCopy = zmg.fastCopylocal makeColor = zmg.makeColorlocal drawPoint = zmg.drawPointlocal keyMenuFast = zmg.keyMenuFastlocal clear = zmg.clearlocal drawText = zmg.drawTextlocal keyDirectPoll = zmg.keyDirectPolllocal keyDirect = zmg.keyDirectlocal floor = math.floorlocal random = math.randomlocal time = zmg.timelocal ticks = zmg.tickslocal copySprite = zmg.copySprite--screen varslocal SCREEN_WIDTH = 384local SCREEN_HEIGHT = 216local exit = 0--game variableslocal key = {F1=79, F2=69, F3=59, F4=49, F5=39, F6=29, Alpha=77, Exit=47, Optn=68, Up=28, Down=37, Left=38, Right=27, EXE=31}local chesstimer = {timerStart=60, add=0, turn="White", turnNum=1, selected=1}local color = {bg=makeColor("white"), fg=makeColor("black"), dbfg=makeColor("red"), dbbg=makeColor("black")}local continue = 0local intro = 1local buffer = 0local timers = {}local playerColor = {makeColor("white"), makeColor("black")}local start=0local timeElapsedSinceTurn = 0local add = 0--first poll and first start timerkeyDirectPoll()local startTime = ticks()--functionslocal function timeElapsed() return floor((ticks()-startTime)/128)endlocal function convertTime(t, format) min = floor(t/60) sec = t-(min*60) if format=="m" then return min elseif format=="s" then return sec endendlocal function wait(timeToWait) local start = timeElapsed() while timeElapsed() - start < timeToWait do endendlocal function waitForKey(key) while keyDirect(key) == 0 do keyDirectPoll() endendlocal function toggleTurn() fastCopy() timers[chesstimer.turnNum + 2] = (timers[chesstimer.turnNum + 2] - timeElapsedSinceTurn) if timers[chesstimer.turnNum + 2] < chesstimer.timerStart then timers[chesstimer.turnNum + 2] = timers[chesstimer.turnNum + 2] + chesstimer.add end if chesstimer.turn == "White" then chesstimer.turn = "Black" chesstimer.turnNum = 2 chesstimer.selected = 2 else chesstimer.turn = "White" chesstimer.turnNum = 1 chesstimer.selected = 1 end start = timeElapsed()end--[[--local function outOfTime(message) clear() drawText(floor(SCREEN_WIDTH/2),floor(SCREEN_HEIGHT/2),message,makeColor("black"), makeColor("red")) fastCopy() waitForKey(key.Exit)end--]]--local function introScreen() clear() continue = 0 drawText(1, 1, "WAIT...", color.fg, color.bg) fastCopy() min = 1 wait(1) while continue==0 do clear() drawText(1, 1, "Press [EXE] to continue", color.fg, color.bg) drawText(1, 20, "Minutes (change with UP/DN): " .. min, color.fg, color.bg) drawText(1, 20, "Time to add after each turn (change with LT/RT): " .. add, color.fg, color.bg) fastCopy() keyDirectPoll() if keyDirect(key.Up)>0 and min<60 then while keyDirect(key.Up) > 0 do keyDirectPoll() end min = min+1 elseif keyDirect(key.Down)>0 and min>1 then while keyDirect(key.Down) > 0 do keyDirectPoll() end min = min-1 end if keyDirect(key.Left)>0 and add<60 then while keyDirect(key.Left) > 0 do keyDirectPoll() end add = add+1 elseif keyDirect(key.Right)>0 and add>0 then while keyDirect(key.Right) > 0 do keyDirectPoll() end add = add-1 end if keyDirect(key.EXE)>0 then continue = 1 end end chesstimer.timerStart = min*60 timers[1] = chesstimer.timerStart timers[2] = chesstimer.timerStart timers[3] = chesstimer.timerStart timers[4] = chesstimer.timerStart chesstimer.add = add intro = 0endlocal function chessTimerScreen() clear() start = timeElapsed() while exit ~= 1 do if keyDirect(key.Exit) > 0 then exit = 1 elseif keyDirect(key.F1) > 0 then while keyDirect(key.F1) > 0 do keyDirectPoll() end toggleTurn() end --drawing clear() drawRectFill(85, (chesstimer.selected * 20) + 43, 10, 10, makeColor("darkblue")) drawText(1, SCREEN_HEIGHT - 20, "Next Player", color.fg, color.bg) drawText(1, 1, "Turn: " .. chesstimer.turn, color.fg, color.bg) drawText(100, 60, "White: " .. convertTime(timers[1],"m") .. ":" .. convertTime(timers[1],"s"), color.fg, color.bg) drawText(100, 80, "Black: " .. convertTime(timers[2],"m") .. ":" .. convertTime(timers[2],"s"), color.fg, color.bg) drawRect(1, 115, SCREEN_WIDTH - 3, 30, color.fg) drawRect(1, 150, SCREEN_WIDTH - 3, 30, color.fg) drawRect(1, 115, (timers[1]*(SCREEN_WIDTH-3))/chesstimer.timerStart, 30, color.fg) drawRectFill(1, 151, (timers[2]*(SCREEN_WIDTH-3))/chesstimer.timerStart, 29, color.fg) fastCopy() --math timeElapsedSinceTurn = timeElapsed() - start timers[chesstimer.turnNum] = timers[chesstimer.turnNum + 2] - timeElapsedSinceTurn if timers[chesstimer.turnNum] < 0 then drawText(1,1,chesstimer.turn .. " ran out of time!",makeColor("black"), makeColor("red")) fastCopy() waitForKey(key.Exit) exit = 1 end --[[-- debug drawText(1, 70, "DEBUG: " .. timers[1], color.dbfg, color.dbbg) --]]-- keyDirectPoll() endend--main loopwhile exit~=1 do clear() --intro screen if intro == 1 then fastCopy() introScreen() end --wait screen clear() drawText(1, 1, "Press F1 when ready", color.fg, color.bg) drawText(1, SCREEN_HEIGHT - 20, "Next Player", color.fg, color.bg) fastCopy() --wait waitForKey(key.F1) --chesstimer screen chessTimerScreen() --refresh screen fastCopy() --keypoll keyDirectPoll()endprint("done.")print("")