--[[
普通 - 48 科学 -45
0-23.
1-1. 2-6. 3-9.
4-11. 5-13. 6-15.
7-17. 8-19. 9-21
+ 25. - 27. × 29. ÷ 31. = 33.
C 37.
( - 87. ) - 85. %-101. x!-81. x^-1 -83.
x^3 -91. x^y-93. √-95. 3√-97. y√x-77.
x^2-89. ln-71. e-79. π-51. rad-99.
log-73. tan-59. cos-57. sin- 55.
lnv-53.
e^x-69. 10^x-75. tan^-1-67. cos^-1-65.
sin^-1-63.
lnv^-1-61.
deg- .
. 43.
显示 输入 104 输出106
等号
print(unpack(A))
]]
--[[
科学计算器
作者:韩永旗
迷你号:247312290
"-----------------------------------------"
0.1 创建科学计算UI界面
0.2 创建UI界面触发器
0.3 创建按钮
0.4 2021.7.19.星期一
功能
1.支持小数混和"+-×÷"混和运算
2.支持一键清除
3.防止连续错误输出
bug
1.等号"="后,"="没有清空,赋值,导致进入新一轮叠加运算 √
2.等号"="后,"+,-,×,÷"没有赋值,清空,导致不能连续运算 √
3.等号"="后,"0123456789"".",导致没有清空,赋值 √
4.没有一个一个退格清除键
5.没有加入错误提醒 √
6.网络时间因触发器计时器变化一秒,导致误差1秒
"-----------------------------------------"
0.5 2021.7.20星期二
1.加入"("")"运算,
2.优化算法
3.加入提示
]]
T={"星期日","星期一","星期二","星期三","星期四","星期五","星期六",}
--界面端
A={
["6985055414249172898_48"]="普通",["6985055414249172898_45"]="科学",
["6985055414249172898_53"]="lnv",["6985055414249172898_61"]="lnv^-1",
["6985055414249172898_104"]="输入",["6985055414249172898_106"]="输出",
["6985055414249172898_37"]="清除",
}
--数字端
B={
["6985055414249172898_1"]=1,["6985055414249172898_6"]=2,["6985055414249172898_9"]=3,
["6985055414249172898_11"]=4,["6985055414249172898_13"]=5,["6985055414249172898_15"]=6,
["6985055414249172898_17"]=7,["6985055414249172898_19"]=8,["6985055414249172898_21"]=9,
["6985055414249172898_23"]=0,["6985055414249172898_43"]=".",
}
--运算符号
C={
["6985055414249172898_25"]="+",["6985055414249172898_27"]="-",
["6985055414249172898_29"]="×",["6985055414249172898_31"]="÷",
["6985055414249172898_33"]="=",
}
--科学运算
D={
["6985055414249172898_87"]="(",["6985055414249172898_85"]=")",
["6985055414249172898_101"]="%",["6985055414249172898_81"]="x!",["6985055414249172898_51"]="π",
["6985055414249172898_79"]="e",["6985055414249172898_83"]="x^-1",["6985055414249172898_89"]="x^2",
["6985055414249172898_91"]="x^3",["6985055414249172898_93"]="x^y",["6985055414249172898_95"]="√(",
["6985055414249172898_97"]="3√",["6985055414249172898_77"]="y√x",["6985055414249172898_99"]="rad",
["6985055414249172898_71"]="ln",["6985055414249172898_69"]="e^x",["6985055414249172898_73"]="log(",
["6985055414249172898_75"]="10^x",["6985055414249172898_55"]="sin(",["6985055414249172898_57"]="cos(",
["6985055414249172898_59"]="tan(",["6985055414249172898_63"]="asin(",["6985055414249172898_65"]="acos(",
["6985055414249172898_67"]="atan(",["6985055414249172898_99"]="deg",
}
--('当前时间:#R'.. timeTable.year .. "年" .. timeTable.month .. "月" .. timeTable.day .. "日"..B[timeTable.wday] .. timeTable.hour .. ":" .. timeTable.min ..
--(tab.year, tab.month, tab.day, B.tab.wday,tab.hour, tab.min, tab.sec)
T1={ "","运算格式错误","运算除数为零错误","运算连续输入错误","括号格式输入错误" }
local A0=[=[6985055414249172898]=]--"界面",
local A1=[=[6985055414249172898_48]=]--"普通",
local A2=[=[6985055414249172898_45]=]--"科学",
local A3=[=[6985055414249172898_53]=]--"lnv",
local A4=[=[6985055414249172898_61]=]--"lnv^-1",
local A5=[=[6985055414249172898_37]=]--"清除",
local A10=[=[6985055414249172898_104]=]--"输入",
local A20=[=[6985055414249172898_106]=]--"输出",
local A30=[=[6985055414249172898_107]=]--"时间",
local A40=[=[6985055414249172898_108]=]--"作者",
local A50=[=[6985055414249172898_109]=]--"错误提示",
--UI界面测试版
a,b,c,n,s,t1={},{},{},{},{},{}
t="0"
k,p,f,d,o,t2,l,o0,s0,s1=1,0,0,0,1,1,0,1,0,0
n[k]=1
a[k]={}
b[k]={}
c[k]={}
print(unpack(a[k]))
print(unpack(b[k]))
local function add4()
a,b,c,n,s,t1={},{},{},{},{},{}
t="0"
local k,p,f,d,o,t2,l,s1,o0=1,0,0,0,1,1,0,0,0
n[k]=1
a[k]={}
b[k]={}
end
k=5
n={6,5,7,3,4}
a={{3,2,1,2,4,0},{1,2,3,4,0},{9,8,7,6,5,4,0},{3,2,0},{4,5,6,6}}
b={{3,1,1,3,1},{3,2,1,1},{1,2,3,1,2,3},{1,3},{1,2,3}}
local function add6() --显示器
if #t<=10 then v4=90
else
for i=1,90 do
if math.floor(1160/y)*math.floor(160/y)-math.floor(1160/y)/2<=#t/2 then
v4=i
break
end
end
end
Trigger.UI:setFontSize(v, A0, A10, v4)
Trigger.UI:setText(v, A0, A10, t)
Trigger.UI:setText(v, A0, A20, s0)
Trigger.UI:setText(v, A0, A50, T1[o])
Trigger.UI:setText(v, A0, A30, Tt)
end
local function add3()
for ii=k,1,-1 do
s[k]=0
if k==1 then
print("k="..k.."n[k]="..n[k])
print(unpack(a[k]))
print(unpack(b[k]))
s[k]=0
if n[k]==1 then s[k]=a[k][n[k]] t=t.."="
else
if b[k][n[k]]~=0 and a[k][n[k]]==nil then t=t.."0" t1[t2]=t t2=t2+1 end
t=t.."="
for i= 1,n[k] do
if b[k][i]==1 then
if (b[k][i+1]~=3 and b[k][i+1]~=4) then s[k]=a[k][i]+a[k][i+1] a[k][i+1]=s[k] a[k][i]=0 b[k][i]=0
elseif b[k][i+1]==3 then if a[k][i+2]~=nil then s[k]=a[k][i+1]*a[k][i+2] a[k][i+1]=a[k][i] a[k][i+2]=s[k] b[k][i+1]=b[k][i] a[k][i]=0 b[k][i]=0 else s[k]=0 a[k][i+1]=a[k][i] a[k][i+2]=s[k] b[k][i+1]=b[k][i] b[k][i]=0 end
elseif b[k][i+1]==4 then if (a[k][i+2]~=0 and a[k][i+2]~=nil) then s[k]=a[k][i+1]/a[k][i+2] a[k][i+1]=a[k][i] a[k][i+2]=s[k] b[k][i+1]=1 a[k][i]=0 b[k][i]=0 else o=2 add4() s0=0 end end
elseif b[k][i]==2 then
if (b[k][i+1]~=3 and b[k][i+1]~=4) then s[k]=a[k][i]-a[k][i+1] a[k][i+1]=s[k] a[k][i]=0 b[k][i]=0
elseif b[k][i+1]==3 then if a[k][i+1]~=nil then s[k]=a[k][i+1]*a[k][i+2] a[k][i+1]=a[k][i] a[k][i+2]=s[k] b[k][i+1]=b[k][i] a[k][i]=0 b[k][i]=0 else s[k]=0 a[k][i+1]=a[k][i] a[k][i+2]=s[k] b[k][i+1]=b[k][i] b[k][i]=0 end
elseif b[k][i+1]==4 then if (a[k][i+2]~=0 and a[k][i+2]~=nil) then s[k]=a[k][i+1]/a[k][i+2] a[k][i+1]=a[k][i] a[k][i+2]=s[k] b[k][i+1]=2 a[k][i]=0 b[k][i]=0 else o=2 add4() s0=0 end end
elseif b[k][i]==3 then s[k]=a[k][i]*a[k][i+1] a[k][i+1]=s[k] a[k][i]=0 b[k][i]=0
elseif b[k][i]==4 then if (a[k][i+1]~=0 and a[k][i+1]~=nil) then s[k]=a[k][i]/a[k][i+1] a[k][i+1]=s[k] a[k][i]=0 b[k][i]=0 else o=2 add4() s0=0 end
end
end
s0=s[k]
s1=s0
end
else
print("k="..k.."n[k]="..n[k])
print(unpack(a[k]))
print(unpack(b[k]))
for i= 1,n[k] do
if b[k][i]==1 then
if (b[k][i+1]~=3 and b[k][i+1]~=4) then s[k]=a[k][i]+a[k][i+1] a[k][i+1]=s[k] a[k][i]=0 b[k][i]=0
elseif b[k][i+1]==3 then if a[k][i+2]~=nil then s[k]=a[k][i+1]*a[k][i+2] a[k][i+1]=a[k][i] a[k][i+2]=s[k] b[k][i+1]=b[k][i] a[k][i]=0 b[k][i]=0 else s[k]=0 a[k][i+1]=a[k][i] a[k][i+2]=s[k] b[k][i+1]=b[k][i] b[k][i]=0 end
elseif b[k][i+1]==4 then if (a[k][i+2]~=0 and a[k][i+2]~=nil) then s[k]=a[k][i+1]/a[k][i+2] a[k][i+1]=a[k][i] a[k][i+2]=s[k] b[k][i+1]=1 a[k][i]=0 b[k][i]=0 else o=2 add6() end end
elseif b[k][i]==2 then
if (b[k][i+1]~=3 and b[k][i+1]~=4) then s[k]=a[k][i]-a[k][i+1] a[k][i+1]=s[k] a[k][i]=0 b[k][i]=0
elseif b[k][i+1]==3 then if a[k][i+1]~=nil then s[k]=a[k][i+1]*a[k][i+2] a[k][i+1]=a[k][i] a[k][i+2]=s[k] b[k][i+1]=b[k][i] a[k][i]=0 b[k][i]=0 else s[k]=0 a[k][i+1]=a[k][i] a[k][i+2]=s[k] b[k][i+1]=b[k][i] b[k][i]=0 end
elseif b[k][i+1]==4 then if (a[k][i+2]~=0 and a[k][i+2]~=nil) then s[k]=a[k][i+1]/a[k][i+2] a[k][i+1]=a[k][i] a[k][i+2]=s[k] b[k][i+1]=2 a[k][i]=0 b[k][i]=0 else o=2 add6() end end
elseif b[k][i]==3 then s[k]=a[k][i]*a[k][i+1] a[k][i+1]=s[k] a[k][i]=0 b[k][i]=0
elseif b[k][i]==4 then if (a[k][i+1]~=0 and a[k][i+1]~=nil) then s[k]=a[k][i]/a[k][i+1] a[k][i+1]=s[k] a[k][i]=0 b[k][i]=0 else o=2 add6() end
end
end
s[k]=a[k][n[k]]
a[k-1][n[k-1]]=s[k]
k=k-1
end
print("k="..(k+1).."n[k]="..n[k+1].."s[k+1]="..s[k+1])
print(unpack(a[k+1]))
print(unpack(b[k+1]))
print(s[k+1])
print(unpack(s))
end
print("s0"..s0)
end
add3()
local function add1()
if k==1 then
if B[v0]=="." then
if a[k][n[k]]==0 or a[k][n[k]]==nil then
if n[k]==1 and a[k][1]==0 then t=t.."." t1[t2]=t t2=t2+1 else t=t.."." t1[t2]=t t2=t2+1 end end
if p==0 then a[k][n[k]]=a[k][n[k]] p=1 t=t..B[v0] t1[t2]=t t2=t2+1 else o=1 end
elseif B[v0]~="." then
if a[k][n[k]]==0 and k==1 and n[k]==1 then t=t t1[t2]=t t2=t2+1 f=0 l=0 else t=t..B[v0] t1[t2]=t t2=t2+1 f=0 l=0 end
if p==0 then a[k][n[k]]=10*a[k][n[k]]+B[v0] else a[k][n[k]]=a[n]+B[v0]*10^(-p) p=p+1 end
end
else
if B[v0]=="." then
if a[k][n[k]]==0 or a[k][n[k]]==nil then
if n[k]==1 and a[k][1]==0 then t=t.."0." t1[t2]=t t2=t2+1 else t=t.."." t1[t2]=t t2=t2+1 end end
if p==0 then a[k][n[k]]=a[k][n[k]] p=1 t=t..B[v0] t1[t2]=t t2=t2+1 else o=1 end
elseif B[v0]~="." then
if a[k][n[k]]==0 and k==1 and n[k]==1 then t="0" t1[t2]=t t2=t2+1 f=0 l=0 else t=t..B[v0] t1[t2]=t t2=t2+1 f=0 l=0 end
if p==0 then a[k][n[k]]=10*a[k][n[k]]+B[v0] else a[k][n[k]]=a[n]+B[v0]*10^(-p) p=p+1 end
end
--elseif (k-1)~=0 and k>1 then ---三角函数
end
end
local function add2()
if o0==0 then
if C[v0]=="=" then
if k~=1 then o=1 add4() s0=0 o0=0
else add3() o0=1 s0=s1 end end
if C[v0]=="("and(f==1 or a[k][n[k]]==0 or a[k][n[k]]==nil) then k=k+1 a[k],b[k],n[k]={},{},1 a[k][n[k]],b[k][n[k]]=0,0 f=1 t=t..C[v0] t1[t2]=t t2=t2+1
elseif C[v0]==")" and f==0 and k~=1 then add3() a[k-1][n[k-1]]=s[k] a[k],b[k],n[k],s[k]={},{},1,0 k=k-1 p=0 t=t..C[v0] t1[t2]=t t2=t2+1
end
if l==1 then o=4 add4() s0=0
elseif l==0 then
if C[v0]=="+" and f==0 then b[k][n[k]]=1 n[k]=n[k]+1 l=1 f=1 p=0 t=t..C[v0] t1[t2]=t t2=t2+1
elseif C[v0]=="-" and f==0 then b[k][n[k]]=2 n[k]=n[k]+1 l=1 f=1 p=0 t=t..C[v0] t1[t2]=t t2=t2+1
elseif C[v0]=="×" and f==0 then b[k][n[k]]=3 n[k]=n[k]+1 l=1 f=1 p=0 t=t..C[v0] t1[t2]=t t2=t2+1
elseif C[v0]=="÷" and f==0 then b[k][n[k]]=4 n[k]=n[k]+1 l=1 f=1 p=0 t=t..C[v0] t1[t2]=t t2=t2+1
end
end
else
if C[v0]=="=" then o0=1 s[k]=s0 t1=s0
elseif C[v0]=="(" then add4() s0=0 o0=0 t="(" t1[t2]=t t2=t2+1 k=k+1 a[k],b[k],n[k]={},{},1 a[k][n[k]],b[k][n[k]]=0,0 f=1
elseif C[v0]==")" then o=4
elseif C[v0]=="+" and f==0 then add4() a[1][1]=s0 o0=0 b[k][n[k]]=1 n[k]=n[k]+1 l=1 f=1 p=0 t=s1..C[v0] t1[t2]=t t2=t2+1 s0=0
elseif C[v0]=="-" and f==0 then add4() a[1][1]=s0 o0=0 b[k][n[k]]=2 n[k]=n[k]+1 l=1 f=1 p=0 t=s0..C[v0] t1[t2]=t t2=t2+1 s0=0
elseif C[v0]=="×" and f==0 then add4() a[1][1]=s0 o0=0 b[k][n[k]]=3 n[k]=n[k]+1 l=1 f=1 p=0 t=s0..C[v0] t1[t2]=t t2=t2+1 s0=0
elseif C[v0]=="÷" and f==0 then add4() a[1][1]=s0 o0=0 b[k][n[k]]=4 n[k]=n[k]+1 l=1 f=1 p=0 t=s0..C[v0] t1[t2]=t t2=t2+1 s0=0
end
end
end
local function add20()
if C[v0]=="("and(f==1 or a[k][n[k]]==0 or a[k][n[k]]==nil) then k=k+1 a[k],b[k],n[k]={},{},1 a[k][n[k]],b[k][n[k]]=0,0 f=1 t=t..C[v0] t1[t2]=t t2=t2+1
elseif C[v0]==")" and f==0 and k~=1 then add3() a[k-1][n[k-1]]=s[k] a[k],b[k],n[k],s[k]={},{},1,0 k=k-1 p=0 t=t..C[v0] t1[t2]=t t2=t2+1
end
end
--显示器
local function M(event)
local timeTable = os.date("*t", timeInterval)
local Tt=timeTable.year.."年"..timeTable.month.."月"..timeTable.day.."日"..T[timeTable.wday]..timeTable.hour..":"..timeTable.min..":"..timeTable.sec
add6()
end
ScriptSupportEvent:registerEvent([=[minitimer.change]=],M)
--玩家点击UI
local function E(param)
v=param.eventobjid
v0=param.btnelenem
Player:playMusic(uid,10786,150,1,false)
if B[v0]~=nil then if y==1 then add4() y=0 s0=0 end add1(B[v0])
elseif C[v0]~=nil then if y==1 then add4() y=0 a[1]=s0 t=s0 end add2(C[v0])
elseif D[v0]~=nil then if y==1 then add4() y=0 a[1]=s0 t=s0 end add2(D[v0])
elseif A[v0]~=nil then
if A[v0]=="清除" then add4() s0=0 y=0 t="0" s=0 o=1
elseif A[v0]=="普通" then
Trigger.UI:hideElement(v, A0, A1)
Trigger.UI:showElement(v, A0, A2)
Trigger.UI:hideElement(v, A0, A4)
Trigger.UI:showElement(v, A0, A3)
elseif A[v0]=="科学" then
Trigger.UI:hideElement(v, A0, A2)
Trigger.UI:showElement(v, A0, A1)
Trigger.UI:hideElement(v, A0, A4)
Trigger.UI:hideElement(v, A0, A3)
elseif A[v0]=="lnv" then
Trigger.UI:showElement(v, A0, A4)
Trigger.UI:hideElement(v, A0, A3)
elseif A[v0]=="lnv-" then
Trigger.UI:showElement(v, A0, A3)
Trigger.UI:hideElement(v, A0, A4)
end
end
--Chat:sendSystemMsg(t)
end
ScriptSupportEvent:registerEvent_NoError([=[UI.Button.Click]=], E)
--玩家进入游戏
local function E3(param)
local v=param.eventobjid
local result,name=Player:getNickname(v)
Player:notifyGameInfo2Self(v,"欢迎玩家"..name.."来到房间")
Player:openUIView(v,A0)
Trigger.UI:hideElement(v, A0, A1)
Trigger.UI:showElement(v, A0, A2)
Trigger.UI:hideElement(v, A0, A4)
Trigger.UI:showElement(v, A0, A3)
end
ScriptSupportEvent:registerEvent_NoError([=[Game.AnyPlayer.EnterGame]=], E3)