LUA- 사용자로부터 명령 줄 입력을 얻습니까?
-
06-07-2019 - |
문제
LUA 프로그램에서는 작업을 진행하기 전에 사용자에게 확인을 중지하고 요청하고 싶습니다. 사용자 입력을 멈추고 기다리는 방법을 잘 모르겠습니다. 어떻게 할 수 있습니까?
해결책
살펴보십시오 io
기본적으로 기본 입력 파일로 표준 입력을 갖는 라이브러리 :
다른 팁
local answer
repeat
io.write("continue with this operation (y/n)? ")
io.flush()
answer=io.read()
until answer=="y" or answer=="n"
나는 이와 같은 코드로 작업했다. 나는 이것을 작동하는 방식으로 입력하겠습니다.
io.write("continue with this operation (y/n)?")
answer=io.read()
if answer=="y" then
--(put what you want it to do if you say y here)
elseif answer=="n" then
--(put what you want to happen if you say n)
end
나는 사용한다:
print("Continue (y/n)?")
re = io.read()
if re == "y" or "Y" then
(Insert stuff here)
elseif re == "n" or "N" then
print("Ok...")
end
Following Code를 사용하십시오
m=io.read()
if m=="yes" then
(insert functions here)
end
print("Continue (y/n)?")
re = io.read()
if re == "y" or "Y" then
(Insert stuff here)
elseif re == "n" or "N" then
print("Ok...")
end
내가 한 LUA의 비트에서 (많이하지 않은), string.sub를 사용하면 대문자와 소문자를 모두 사용하는 것이 중복이라고 말할 것입니다.
print("Continue? (y/n)")
local re = io.read()
--[[Can you get string.sub from a local var?
If so, this works. I'm unfamiliar with io(game
lua uses GUI elements and keypresses in place of the CLI.]]
if re.sub == "y" then
--do stuff
if re.sub == "n" then
--do other stuff
end
작동해야합니다.
제휴하지 않습니다 StackOverflow