【发布时间】:2012-02-06 21:35:04
【问题描述】:
我一直在四处寻找,但找不到任何对我有用的东西。我开始学习更多 Lua 并且开始我正在制作一个简单的计算器。我能够将每个单独的操作放到单独的程序上,但是当我尝试将它们组合起来时,我就是无法让它工作。我现在的脚本是
require "io"
require "operations.lua"
do
print ("Please enter the first number in your problem.")
x = io.read()
print ("Please enter the second number in your problem.")
y = io.read()
print ("Please choose the operation you wish to perform.")
print ("Use 1 for addition, 2 for subtraction, 3 for multiplication, and 4 for division.")
op = io.read()
op = 1 then
function addition
op = 2 then
function subtraction
op = 3 then
function multiplication
op = 4 then
function division
print (answer)
io.read()
end
我的 operations.lua 脚本是
function addition
return answer = x+y
end
function subtraction
return answer = x-y
end
function multiplication
return answer = x*y
end
function division
return answer = x/y
end
我尝试过使用
if op = 1 then
answer = x+y
print(answer)
if op = 2 then
answer = x-y
print(answer)
我完成了每个操作。但它不起作用。我什至无法得到它返回的错误代码,因为它关闭得太快了。我该怎么办?
【问题讨论】:
标签: function lua calculator