2014-07-17 7 views
2
function calculateGainOverHrs(dronenum, hrs) 
    local yypx = 0 
    for hrs=hrs,0,-1 
    do 
     yypx = yypx + calculateGainHour(dronenum) 
    end 
    return yypx 
end 

나는 광산 시설에서 확보하고 얼마나 많은 돈을 계산하는 프로그램을 만들려고 해요 (물론, 게임을 (.))에 대한 루아의 최소값 근처 기대했다. 위의 함수를 사용하여 특정 시간 동안의 이득을 계산했습니다. 그러나 그것을 실행하면이 오류가 발생합니다 -'<name>은'루프

\LUAPrograms\miningalgoluaport.lua:29: '<name>' expected near '0' 

이 질문의 특수성으로 인해 검색 할 수 없습니다. 나는 수정이 있다고 확신하지만, hrs 인수를 함수에 넣기 만하면된다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

편집 : 스크립트는 다음과 같습니다 -

-- Ores -- 
Cop = 5 
Iro = 10 
Sil = 150 
Gol = 250 
Pla = 400 
Dia = 1000 
Aeg = 1300 
Cer = 1700 
Rub = 2300 
Ura = 1300 
Plu = 2100 
Sol = 4000 
-- Ores -- 

drones = nil 
totalpx = 0 

math.randomseed(os.time * 42420451 * 425714 * 0.23) 
math.randomseed(math.random(1,29214757862396238564328976)) 

function calculateGainOverDays(dronenum, days) 
    yyypxyyy = calculateGainOverHrs(dronenum, 24) * days 
    return yyypxyyy 
end 

function calculateGainOverHrs(dronenum, hrs) 
    local yypx = 0 
    for hrs,0,-1 
    do 
     yypx = yypx + calculateGainHour(dronenum) 
    end 
    return yypx 
end 

function calculateGainHour(dronenum) 
    local ypx = 0 
    orenum = math.random(1,30) 
    for orenum,0,-1 
    do 
     ore = randint(1, 100) 
     if (ore >= 1 and ore <= 5) 
      px += Cop * dronenum 
     end 
     else if (ore >= 6 and ore <= 30) 
      px += Iro * dronenum 
     end 
     else if (ore >= 31 and ore <= 52) 
      px += Sil * dronenum 
     end 
     else if (ore >= 53 and ore <= 62) 
      px += Gol * dronenum 
     end 
     else if (ore >= 63 and ore <= 70) 
      px += Pla * dronenum 
     end 
     else if (ore >= 71 and ore <= 77) 
      px += Dia * dronenum 
     end 
     else if (ore >= 78 and ore <= 87) 
      px += Aeg * dronenum 
     end 
     else if (ore >= 88 and ore <= 90) 
      px += Cer * dronenum 
     end 
     else if (ore == 91) 
      px += Rub * dronenum 
     end 
     else if (ore >= 92 and ore <= 97) 
      px += Plu * dronenum 
     end 
     else if (ore >= 98 and ore <= 100) 
      px += Sol * dronenum 
     end 
    end 
    return px 
end 

function menuDisplay() 
    print 
    (
    "1 - Calculate Ore Gain\n".. 
    "2 - Change Drone Number\n".. 
    "Total Pixels this Session: " .. tostring(totalpx) 
    end 
    ) 
    if (io.read = 1) 
     print 
     (
     "1 - Over Days \n".. 
     "2 - Over Hours \n".. 
     "3 - Over an Hour" 
     ) 
     if (io.read() = 1) 
      io.write("How many days?") 
      local tempI = nil 
      local tempII = io.read 
      tempI = calculateGainOverDays(drones,tempII) 
      print("The facility generated " .. tempI .. "px over" .. tempII .. "days.") 
      totalpx = totalpx + tempI 
      menuDisplay() 
     end 
     else if (io.read() = 2) 
      io.write("How many hours?") 
      local tempI = nil 
      local tempII = io.read 
      tempI = calculateGainOverHrs(drones,tempII) 
      print("The facility generated " .. tempI .. "px over" .. tempII .. "hours.") 
      totalpx = totalpx + tempI 
      menuDisplay() 
     end 
     else if (io.read() = 3) 
      local tempI = calculateGainHour(drones) 
      print("In one hour, the facility generated " .. temp1 .. "px." 
      totalpx = totalpx + tempI 
      menuDisplay() 
     end 
    else if (io.read = 2) 
     io.write("New Dronenum:") 
     drones = io.read 
     menuDisplay() 
    end 
end 





--!CORE!-- 
--!CORE!-- 
--!CORE!-- 
--!CORE!-- 
--!CORE!-- 
print("Vernet Industries Ore Calculator - Created by Maurice Vernet") 

print("Initializing...") 

io.write("Enter Number of Drones:") 

drones = io.read() 

menuDisplay() 
+0

@PaulKulchenko와의 계약에 따라 코드는 5.1 및 5.2 모두에서 작동합니다. 그 코드가 관련 됐는지 확신합니까? –

+0

코드 조각'calculateGainOverHrs'와 전체'calculateGainOverHrs' 함수를 비교하면 코드 조각에서 변경 한 내용이 나타나 문제를 해결할 수 있습니다. –

+0

IDE (예 : [Koneki] (http://www.eclipse.org/koneki/ldt/))는 입력하는 동안 오류를 발견하는 데 도움이 될 수 있습니다. 그런 다음 특정 질문을 할 수 있습니다. –

답변

3

전체 스크립트에 많은 구문 오류가 있습니다. 여기에 그들 중 일부는 다음과 같습니다

  1. 당신은 if 문에서 then를 놓쳤다. 또한 elseif은 루아에있는 키워드이며, else if보다 더 선호하는 것은 end이 필요 없기 때문입니다. 예를 들어 :

    if (ore >= 1 and ore <= 5) 
        --do something 
    end  
    else if (ore >= 6 and ore <= 30) 
        --do something else 
    end 
    

    루아에는 복합 대입이 없습니다
    if ore >= 1 and ore <= 5 then 
        --do something 
    elseif ore >= 6 and ore <= 30 then 
        --do something else 
    end 
    
  2. px += Iro * dronenum 
    

    px = px + Iro * dronenum 
    
  3. io.read가해야해야 함수 자체는 io.read()이 함수의 반환 값이지만 여러 위치에서 잘못 사용하고 있습니다.

0

iBook의 루아 코드를 텍스트 편집기 (하위 텍스트 3)에 복사하여 붙여 넣으려고하면이 문제가 발생합니다. 표시 될 수도 있고 표시되지 않을 수도있는 특수 문자가 추가되어 나타납니다.

내 편집기의 구문이 올바르지 않아서 함수를 다시 입력했음을 확인했습니다. 뿐만 아니라 작동하지만 구문은 붙여 넣은 코드와 다릅니다.