已解决。LUA如何锁定鼠标单击,以使指示灯不会快速闪烁。我必须创建闩锁,闩锁= 0,然后在lights()函数中,比较闩锁和ms [3]不同或相同时的情况,以及每种情况下的操作。
lToggle = {cs=0,x1=1,x2=40,y1=1,y2=40}
ms = {}
latch = 0
function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
if numDecimalPlaces ~= nil then
return math.floor(num * mult + 0.5) / mult
else
return math.floor((num * mult + 0.5) / mult)
end
end
function msState(v)
return {round(v.getMouseX() * 100,1),round(v.getMouseY() * 100,1),v.getMouseState()}
end
function lights()
ms = msState(screen)
if ms[3] == 1 and latch == 0
then
latch = 1
elseif ms[3] == 0 and latch == 1
then
latch = 0
if ms[1] >= lToggle.x1 and ms[1] <= lToggle.x2 and ms[2] >= lToggle.y1 and ms[2] <= lToggle.y2
then
light.toggle()
else end
else end
end
function html()
screen.setHTML([[<html><body>
<style>
#test {
position: absolute;
top: 50%;
left: 50%;
font-size: 40px;
color: green;
}
#test2 {
position: absolute;
top: 20%;
left: 20%;
width: 30%;
height: 30%;
font-size: 40px;
color: green;
border: 5px solid red;
}
</style>
<span id="test">Test</span>
<span id="test2"> X:]].. ms[1] ..[[ </br>Y:]].. ms[2]..[[</br>Click State:]].. ms[3] ..[[</span>
<!-- <span id="test2"></span>-->
</body></html>]])
end
然后在system.update()中为:
screen.clear()
lights()
html()
此问题已解决。我在开头添加了闩锁= 0,并将其更改为:
function lights()
ms = msState(screen)
if ms[3] == 1
then
if ms[1] >= lToggle.x1 and ms[1] <= lToggle.x2 and ms[2] >= lToggle.y1 and ms[2] <= lToggle.y2
then
light.toggle()
else end
else end
end
收件人:
function lights()
ms = msState(screen)
if ms[3] == 1 and latch == 0
then
latch = 1
elseif ms[3] == 0 and latch == 1
then
latch = 0
if ms[1] >= lToggle.x1 and ms[1] <= lToggle.x2 and ms[2] >= lToggle.y1 and ms[2] <= lToggle.y2
then
light.toggle()
else end
else end
end