Я довольно новичок в Lua, и я кодирую программу. Программа представляет собой письмо, собирающееся и собирающее другие буквы (вроде программы червя). Тем не менее, я хочу, чтобы это было приурочено. (Я на computercraft, который является мод для minecraft, но все еще использует Lua, поэтому я не думаю, что это важно). Я использую os.PullEvent («ключ»), чтобы я мог перемещать письмо, но os. pullEvent() приостанавливает выполнение программы до тех пор, пока она не будет удовлетворена. Моя проблема в том, что я хочу, чтобы таймер постоянно тикал одновременно. Любые идеи относительно того, как я мог это сделать? Благодаря!Добавление таймера к моей программе Lua
term.clear()
w = 1
h = 1
score = 0
function topLine()
term.setTextColor(colors.orange)
term.setCursorPos(5,1)
print("Score: ", score)
end
function randLoc()
w,h = math.random(2,50) , math.random(3,17)
term.setCursorPos(w,h)
term.setTextColor(colors.red)
print"O"
end
function drawBorder()
term.setTextColor(colors.blue)
term.setCursorPos(1,2)
print"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
print"X X"
print"X X"
print"X X"
print"X X"
print"X X"
print"X X"
print"X X"
print"X X"
print"X X"
print"X X"
print"X X"
print"X X"
print"X X"
print"X X"
print"X X"
print"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
end
function checkTouch()
if x ~= w or y ~= h then
term.setCursorPos(w,h)
term.setTextColor(colors.red)
print"O"
elseif x == w and y == h then
w,h = math.random(2,50) , math.random(3,17)
term.setCursorPos(w,h)
term.setTextColor(colors.red)
print"O"
score=score+1
end
end
x = 2
y = 3
randLoc()
while true do
topLine()
drawBorder()
checkTouch()
term.setCursorPos(x,y)
term.setTextColor(colors.lime)
print"T"
local e,move = os.pullEvent("key")
if move == 30 or move == 203 then
x=x-1
if x <= 1 then
x = 2
end
end
if move == 32 or move == 205 then
x=x+1
if x >= 51 then
x = 50
end
end
if move == 31 or move == 208 then
y=y+1
if y >= 18 then
y = 17
end
end
if move == 17 or move == 200 then
y=y-1
if y <= 2 then
y = 3
end
end
term.clear()
end
Вы можете просто использовать 'print ((« X »): rep (50))' для границ. – hjpotter92
Спасибо! Имейте это в виду! – user1510082