2011-04-17 66 views
1

執行此代碼時,我得到一個錯誤「試圖調用全球‘FORID’(一個零值)」的Lua - 嘗試調用全局(一個零值)

function execute(args) 
    local itemid = 526 
    local bone = forId(itemid) -- this is where the error occurs 
end 

function forId(bid) 
    local xp = 0.0 
    if bid == 526 or bid == 528 or bid == 2530 or bid == 2859 then 
     xp = 4.5 
    elseif bid == 3179 or bid == 3180 or bid == 3183 or bid == 3185 then 
     xp = 5.0 
    elseif bid == 530 then 
     xp = 53 
    elseif bid == 532 or bid == 3125 then 
     xp = 15 
    elseif bid == 4812 then 
     xp = 22.5 
    elseif bid == 7839 then 
     xp = 30 
    elseif bid == 6812 then 
     xp = 50 
    elseif bid == 536 then 
     xp = 72 
    end 
    local bone = Bone:new(bid, xp) 
    return bone 
end 

Bone = class(function(b, id, xp) 
    b.id = id 
    b.xp = xp 
end) 

誰能告訴我爲什麼

回答

1

嘗試緩存它作爲當地第一,特別是如果你使用module

local forId = forId //or _G.forId 
local bone = forId(itemid) 
+0

這有什麼區別,如果它是首先作爲本地緩存? – 2014-05-14 22:19:04

6

Lua的過程,並通過行執行文件行,以便順序定義和使用它們可能是重要的。在這種情況下。儘管看起來你沒有提供所有的代碼,因爲它看起來像是將forID定義爲全局的,但錯誤意味着其他情況。您可以簡單地嘗試更改函數定義的順序,以查看它是否有效。

Bone = class(function(b, id, xp) 
    b.id = id 
    b.xp = xp 
end) 

function forId(bid) 
    local xp = 0.0 
    if bid == 526 or bid == 528 or bid == 2530 or bid == 2859 then 
     xp = 4.5 
    elseif bid == 3179 or bid == 3180 or bid == 3183 or bid == 3185 then 
     xp = 5.0 
    elseif bid == 530 then 
     xp = 53 
    elseif bid == 532 or bid == 3125 then 
     xp = 15 
    elseif bid == 4812 then 
     xp = 22.5 
    elseif bid == 7839 then 
     xp = 30 
    elseif bid == 6812 then 
     xp = 50 
    elseif bid == 536 then 
     xp = 72 
    end 
    local bone = Bone:new(bid, xp) 
    return bone 
end 

function execute(args) 
    local itemid = 526 
    local bone = forId(itemid) -- this is where the error occurs 
end 

但是,由於您沒有提供完整的代碼,這可能只是導致錯誤轉移到其他地方。

0

我想,你應該包括在第一個庫文件,如IE

dofile(core.app_path() .. "\\strategies\\standard\\include\\helper.lua"); 

(確切的命令可以在軟件的紀錄片中找到。)

相關問題