0 Members and 1 Guest are viewing this topic.
answer = "" --This is the error, i'm getting "unexpected symbol near 'char(226)" D: function on.charIn(char) answer = answer..char var.store("line3",answer) -- Refresh the screen after each key is pressed. platform.window:invalidate() end function on.backspaceKey() answer = answer:usub(0,-2) var.store("line3",answer) platform.window:invalidate() end
menu = {{text = "small", selected = true, id = 1}, {text = "larger", selected = false, id = 2}, {text = "even larger", selected = false, id = 3}, {text = "sml", selected = false, id = 4}}--our menu menuDrawn = false--menu flagfunction on.paint(gc) gc:setFont("serif", "r",7) if menuDrawn then --dynamicly find the width local width = 0 local strHld = 0 for i = 1, table.maxn(menu) do strHld = gc:getStringWidth(menu[i].text) if strHld > width then width = strHld + 1 end end strHld = gc:getStringHeight("Hh") --find the strings height local height = strHld * table.maxn(menu)--find the total height --fill grey rectangle gc:setColorRGB(175, 175, 175) gc:fillRect(0, 0, width, height) --draw black rectangle gc:setColorRGB(0, 0, 0) gc:drawRect(0, 0, width, height) --draw the strings local y = 5 for i = 1, table.maxn(menu) do if menu[i].selected then --reverse video gc:fillRect(0, y - 6, width, strHld) gc:setColorRGB(255, 255, 255) gc:drawString(menu[i].text, 1, y, "middle") gc:setColorRGB(0, 0, 0) else gc:drawString(menu[i].text, 1, y, "middle") end gc:drawLine(0, y + 7, width, y + 7) y = y + strHld end endendfunction on.contextMenu() --pressed ctrl+menu menuDrawn = not(menuDrawn)endfunction on.arrowUp() --up arrow was pressed local fnd = findCurSelection() if menu[fnd].id ~= 1 then menu[fnd - 1].selected = true else menu[table.maxn(menu)].selected = true end menu[fnd].selected = false platform.window:invalidate()endfunction on.arrowDown() --down arrow was pressed local fnd = findCurSelection() if menu[fnd].id ~= table.maxn(menu) then menu[fnd + 1].selected = true else menu[1].selected = true end menu[fnd].selected = false platform.window:invalidate()endfunction on.enterKey() --enter key was pressed menu[findCurSelection()].text = "You pressed Enter" platform.window:invalidate()endfunction findCurSelection() --find the current selected item for i = 1, table.maxn(menu) do if menu[i].selected then return i end endend