【发布时间】:2020-07-23 15:02:51
【问题描述】:
我只想在按下“+”键时执行 findSum() 函数。所以当我按“+”键时, 必须调用函数 findSum()。 到目前为止,这是我的程序:
numberOfInput = 0
sum = 0
io.write('\t', "Welcome to My Calculator", '\n')
repeat
io.write("for addition, press '+' :", '\n')
findSumSection = io.read()
until
(string.match(findSumSection, '+'))
function findSum()
io.write("Enter the amount of feed(s):",'\n')
numberOfInput = io.read()
x = numberOfInput
for i = 1, x, 1 do
io.write('\n',"enter the number: ")
inputs = io.read()
sum = sum + inputs
end
return sum
end
io.write('\n',"The Sum of your feeds is:", '\n' , findSum(), '\n')
io.write("Do you want to continue? [Y/N]")
inputYesorNo = io.read()
if (string.match(inputYesorNo, 'yes')) then
print("Starting the program again")
else if(string.match(inputYesorNo, 'no')) then
os.exit()
else
print("The program can not understand the procedure")
end
end
【问题讨论】:
-
我认为您的问题可以更简洁。改变这个: ** 只想在按下“+”键时执行 findSum() 函数。所以当我按“+”键时,必须调用函数 findSum()。到目前为止,这是我的程序:** 到此:如何知道何时按下“+”键 并删除/使您的代码更短。还请务必在互联网上搜索我更正的问题,因为它似乎是一个无处不在的话题。还为您尝试完成任务的环境提供上下文。查看:stackoverflow.com/questions/5689566/keypress-event-in-lua
-
这能回答你的问题吗? KeyPress event in Lua?
-
感谢您的帮助。我非常感谢。我刚刚在另一个程序中测试了同样的问题并得到了解决。
标签: function keypress execution