我已經收到以下錯誤與這部分代碼:的Lua試圖索引全球的「自我」的錯誤(GMOD的Lua腳本)
[ERROR] lua/entities/cook/init.lua:58: attempt to index global 'self' (a nil value)1. cooked - lua/entities/cook/init.lua:58
功能開始於第57行,當我刪除線58 (local Pos = self.Entity:GetPos()
,它只是給出了線相同的錯誤消息61
function cooked()
local Pos = self.Entity:GetPos()
local roll = math.random(1, 5);
if roll == 5 then
self.Entity:EmitSound("phx/explode06.wav")
self.Entity:Remove()
else
local createfood = ents.Create("food")
createfood:SetPos(Pos + Vector(0,10,100))
createfood:Spawn()
self:SendLua("GAMEMODE:AddNotify(\"You finish cooking the food and package the product!\", NOTIFY_GENERIC, 4)")
end
end
爲什麼你接受迷宮的答案,但不是湯姆的,這不僅是正確的,而且還解釋了爲什麼? – nonchip