Tiny-Metro / Poly-Metro

Make subway line simulation game
GNU General Public License v3.0
6 stars 0 forks source link

lua Investment.1003 nil 오류 #351

Closed seong0929 closed 1 year ago

seong0929 commented 1 year ago

image

LogLuaMachine: Error: Lua error: attempt to call a nil value_ LogLuaMachine: Error: Lua error: ...Content/Script/Investment/SavedSeoul/Investment.1003.lua:29: attempt to index a nil value (field '?') LogLuaMachine: Error: Lua error: attempt to call a nil value


-- Complaint management
local additional_needs_1003 = 50
local reward_money_1003 = 800

-- Investment condition
function InvestmentData()
    local Data = {}
    Data.message = '어떤 역도 불만도 ' .. additional_needs_1003 .. '을 넘지 않도록 하세요.'
    Data.time_require = 7
    Data.award = reward_money_1003 .. "$"

    return Data
end

-- Call when investment start
-- Used save info when start
function Start()
end

-- Investment appear condition
function Appearance()
    local stations = GetStationInfos()

    if stations == nil then
        return false
    end

    for i=0, #stations do
        -- 아래 조건부에서 오류가 발생했습니다.
        if stations[i].Complain > additional_needs_1003 then
            return false
        end
    end
    return true
end

-- Investment success condition
function Process()
    local start_time = GetTimestampAtStart(1003)
    local cur_time = GetTimestamp()
    local stations = GetStationInfos()

    local all_stations_limit = true

    for i = 0, #stations do
        if stations[i].Complain > additional_needs_1003 then
            -- If the deadline is exceeded, it immediately fails.
            all_stations_limit = false
            break
        end
    end

    if all_stations_limit then
        if (start_time.Date - cur_time.Date) <= InvestmentData().time_require then
            return continue
        else
            return success
        end
    else
        return fail
    end
end

-- Investment award
function Award()
    AddMoney(reward_money_1003)
end

InvestmentDataStruct= {}
InvestmentDataStruct.InvestmentData = InvestmentData
InvestmentDataStruct.Start = Start
InvestmentDataStruct.Appearance = Appearance
InvestmentDataStruct.Process = Process
InvestmentDataStruct.Award = Award

return InvestmentDataStruct

ruru14 commented 1 year ago

API가 아니라 코드문제같습니다. 이하 코드 정상 작동합니다.

stations = GetStationInfos()
for i, v in pairs(stations) do
    print(v.Complain) 
end
ruru14 commented 1 year ago

추가로, Lua코드에 대한 간단한 테스트 기능을 만들어놨었는데, 해당 기능 공유합니다. image 콘솔 UI의 Call TestFunction버튼을 클릭할 시, 아래 경로의 TestFunction함수가 호출됩니다.
Content/Script/TestScript.lua
테스트 시 이용 바랍니다.