我一直在環顧四周,我一直無法找到任何對我有用的東西。我開始學習更多的Lua並開始製作一個簡單的計算器。我能夠將每個單獨的操作都放到單獨的程序中,但是當我嘗試將它們合併時,我無法使其運行。我的腳本,它現在是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)
嘗試和我這樣做,在完成各項操作。但它不起作用。我什至不能得到它返回的錯誤代碼,因爲它關閉得這麼快。我該怎麼辦?
謝謝,當我回家時,我會盡力處理它。沒有SciTE的工作很難,因爲我無法找到解決它的錯誤。 – crazyman10123 2012-01-10 16:14:31