修复计算器e键非法输入报错

This commit is contained in:
MrZ626
2020-10-13 10:42:16 +08:00
parent e89a4c682d
commit 285af92d88

View File

@@ -47,10 +47,6 @@ do--calculator
end
mouseDown.calculator=NULL
local function EGG(str)
sceneTemp.reg=str
sceneTemp.sym="="
end
function keyDown.calculator(k)
local S=sceneTemp
if byte(k)>=48 and byte(k)<=57 then
@@ -68,6 +64,10 @@ do--calculator
end
elseif k=="."then
if not(find(S.val,".",nil,true)or find(S.val,"e"))then
if S.sym and not S.reg then
S.reg=S.val
S.val="0."
end
S.val=S.val.."."
end
elseif k=="e"then
@@ -75,7 +75,13 @@ do--calculator
S.val=S.val.."e"
end
elseif k=="backspace"then
if S.sym=="="then
S.val=""
elseif S.sym then
S.sym=false
else
S.val=sub(S.val,1,-2)
end
if S.val==""then S.val="0"end
elseif k=="+"or k=="="and kb.isDown("lshift","rshift")then
S.sym="+"
@@ -90,8 +96,9 @@ do--calculator
S.sym="/"
S.reg=false
elseif k=="return"then
if S.val then
if byte(S.val,-1)==101 then S.val=sub(S.val,1,-2)end
if S.sym and S.reg then
if byte(S.reg,-1)==101 then S.reg=sub(S.reg,1,-2)end
S.val=
S.sym=="+"and (tonumber(S.reg)or 0)+tonumber(S.val)or
S.sym=="-"and (tonumber(S.reg)or 0)-tonumber(S.val)or
@@ -121,7 +128,6 @@ do--calculator
S.pass=true
SCN.go("debug")
end
end
elseif k=="escape"then
S.val,S.reg,S.sym="0"
elseif k=="delete"then