2016-06-20 16 views
-1

私はGMODゲームモードで本当に面倒なエラーが発生しました。私は、カスタムメニューを作成しようとしていますが、私はこのエラーを取得する:ここでグローバル 'addButtons'(ゼロ値)を呼び出そうとしました

[ERROR] gamemodes/tdm/gamemode/custom_menu.lua:20: attempt to call global 'addButtons' (a nil value) 
    1. gameMenu - gamemodes/tdm/gamemode/custom_menu.lua:20 
    2. unknown - gamemodes/tdm/gamemode/custom_menu.lua:32 
    3. include - [C]:-1 
    4. unknown - gamemodes/tdm/gamemode/cl_init.lua:3 

は私のコードです:

custom_menu.lua

local Menu 

function gameMenu() 
    if(Menu == nil) then 
     Menu = vgui.Create("DFrame") 
     Menu:SetSize(750, 500) 
     Menu:SetPos(ScrW()/2 - 325, ScrH()/2 - 250) 
     Menu:SetTitle("Gamemode Menu") 
     Menu:SetDraggable(true) 
     Menu:ShowCloseButton(false) 
     Menu:SetDeleteOnClose(false) 
     Menu.Paint = function() 
      surface.SetDrawColor(60, 60, 60, 255) 
      surface.DrawRect(0, 0, Menu:GetWide(), Menu:GetTall()) 

      surface.SetDrawColor(40, 40, 40, 255) 
      surface.DrawRect(0, 24, Menu:GetWide(), 1) 
     end 

     addButtons(Menu) 
     gui.EnableScreenClicker(true) 
    else 
     if(Menu:IsVisible()) then 
      Menu:SetVisible(false) 
      gui.EnableScreenClicker(false) 
     else 
      Menu:SetVisible(true) 
      gui.EnableScreenClicker(true) 
     end 
    end 
end 
concommand.Add("open_game_menu", gameMenu()) 

function addButtons(Menu) 
    local playerButton = vgui.Create("DButton") 
    playerButton:SetParent(Menu) 
    playerButton:SetText("") 
    playerButton:SetSize(100, 50) 
    playerButton:SetPos(0, 25) 
    playerButton.Paint = function() 
     --Color of entire button 
     surface.SetDrawColor(50, 50, 50, 255) 
     surface.DrawRect(0, 0, playerButton:GetWide(), playerButton:GetTall()) 

     --Draw Bottom and Right borders 
     surface.SetDrawColor(40, 40, 40, 255) 
     surface.DrawRect(0, 49, playerButton:GetWide(), 1) 
     surface.DrawRect(99, 0, 1, playerButton:GetTall()) 

     --Draw Text 
     draw.DrawText("Player", "DermaDefaultBold", playerButton:GetWide()/2, 17, Color(255, 255, 255, 255), 1) 
    end 

    playerButton.DoClick = function(playerButton) 
     local playerPanel = Menu:Add("PlayerPanel") 
    end 
    local shopButton = vgui.Create("DButton") 
    shopButton:SetParent(Menu) 
    shopButton:SetText("") 
    shopButton:SetSize(100, 50) 
    shopButton:SetPos(0, 75) 
    shopButton.Paint = function() 
     --Color of entire button 
     surface.SetDrawColor(50, 50, 50, 255) 
     surface.DrawRect(0, 0, shopButton:GetWide(), shopButton:GetTall()) 

     --Draw Bottom and Right borders 
     surface.SetDrawColor(40, 40, 40, 255) 
     surface.DrawRect(0, 49, shopButton:GetWide(), 1) 
     surface.DrawRect(99, 0, 1, shopButton:GetTall()) 

     --Draw Text 
     draw.DrawText("Shop", "DermaDefaultBold", shopButton:GetWide()/2, 17, Color(255, 255, 255, 255), 1) 
    end 

    shopButton.DoClick = function(shopButton) 
     local shopPanel = Menu:Add("ShopPanel") 
    end 
end 



--Player Panel 

PANEL = {} -- Create an empty panel 

function PANEL:Init() --Initialize the panel 
    self:SetSize(650, 475) 
    self:SetPos(100, 25) 
end 

function PANEL:Paint(w, h) 
    draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 255)) 
end 

vgui.Register("PlayerPanel", PANEL, "Panel") 

--End Player Panel 

--Shop Panel 

PANEL = {} -- Create an empty panel 

function PANEL:Init() --Initialize the panel 
    self:SetSize(650, 475) 
    self:SetPos(100, 25) 
end 

function PANEL:Paint(w, h) 
    draw.RoundedBox(0, 0, 0, w, h, Color(255, 255, 255, 255)) 
end 

vgui.Register("ShopPanel", PANEL, "Panel") 

--End Shop Panel 

init.lua:

AddCSLuaFile("shared.lua") 
AddCSLuaFile("cl_init.lua") 
AddCSLuaFile("testhud.lua") 

local open = false 

include ('shared.lua') 

local open = false 

function GM:PlayerInitialSpawn(ply) 
    if(ply:GetPData("playerLvl") == nil) then 
     ply:SetNWInt("playerLvl", 1) 
    else 
     ply:SetNWInt("playerLvl", ply:GetPData("playerLvl")) 
    end 
    if(ply:GetPData("playerExp") == nil) then 
     ply:SetNWInt("playerExp", 0) 
    else 
     ply:SetNWInt("playerExp", ply:GetPData("playerExp")) 
    end 
    if(ply:GetPData("playerMoney") == nil) then 
     ply:SetNWInt("playerMoney", 0) 
    else 
     ply:SetNWInt("playerMoney", ply:GetPData("playerMoney")) 
    end 
end 

function GM:OnNPCKilled(npc, attacker, inflictor) 

    attacker:SetNWInt("playerMoney", attacker:GetNWInt("playerMoney") + 100) 

    attacker:SetNWInt("playerExp", attacker:GetNWInt("playerExp") + 100) 

    checkForLevel(attacker) 

end 

function GM:PlayerDeath(victim, inflictor, attacker) 

    attacker:SetNWInt("playerMoney", attacker:GetNWInt("playerMoney") + 100) 

    attacker:SetNWInt("playerExp", attacker:GetNWInt("playerExp") + 100) 

    checkForLevel(attacker) 

end 

function GM:PlayerLoadout(ply) 
    ply:Give("m9k_l85") 
    ply:Give("m9k_colt1911") 
    ply:Give("m9k_knife") 
    ply:Give("m9k_m61_frag") 

    ply:GiveAmmo(500, "ar2", true) 
    ply:GiveAmmo(100, "pistol", true) 

    return true 
end 

function checkForLevel(ply) 
    local expToLevel = (ply:GetNWInt("playerLvl") * 100) * 2 
    local curExp = ply:GetNWInt("playerExp") 
    local curLvl = ply:GetNWInt("playerLvl") 

    if(curExp >= expToLevel) then 
     curExp = curExp - expToLevel 

     ply:SetNWInt("playerExp", curExp) 
     ply:SetNWInt("playerLvl", curLvl + 1) 
    end 
end 

function GM:PlayerDisconnected(ply) 
    ply:SetPData("playerExp", ply:GetNWInt("playerExp")) 
    ply:SetPData("playerLvl", ply:GetNWInt("playerLvl")) 
    ply:SetPData("playerMoney", ply:GetNWInt("playerMoney")) 
end 

function GM:ShutDown() 
    for k, v in pairs(player.GetAll()) do 
     v:SetPData("playerExp", v:GetNWInt("playerExp")) 
    v:SetPData("playerLvl", v:GetNWInt("playerLvl")) 
    v:SetPData("playerMoney", v:GetNWInt("playerMoney")) 
    end 
end 

function GM:ShowSpare2(ply) 
    ply:ConCommand("open_game_menu") 
end 

ありがとう!

-Graham

+0

完全なエラーメッセージを含めてください。 [mcve] –

+0

を作成しても、それを自分で修正しようとしましたか?私はそれがエラーメッセージのすべてであることを意味します。あなたはちょうど与えられた行に行き、何が起こっているか見る必要があります... – Piglet

答えて

0

あなたは関数定義はconcommand.Add("open_game_menu", gameMenu())後、以下のように、この時点でnilあるaddButtons(Menu)を呼び出し

concommand.Add("open_game_menu", gameMenu()) 

を呼び出します。

すべてです。エラーメッセージを読むだけでいいです。

スクリプトの順序を変更してエラーを修正してください。

関連する問題