attempt to index global (a nil value)

local dropped_item = nil
local is_cigarettepack = false

function spawn_item(obj, item)
if obj then
obj = alife():create(item, obj:position(), obj:level_vertex_id(), obj:game_vertex_id(), obj:id())
return obj.id
end

return nil
end

– ************************************************** ************* –

local cigarette = Cigarette()

function on_item_drop(obj)
if not has_alife_info(“ui_inventory”) then
return
end

if string.find(obj:section(), “cigarettepack_”) then
is_cigarettepack = true
dropped_item = obj:id()
end
end

function check_dropped_item()
if dropped_item and is_cigarettepack then
id not alife():object(dropped_item) then
string.find(obj:section, “cigarettepack_s25”) then
spawn_item(db.actor, “cigarettepack_s24”)
end
end
end
end

is_cigarettepack = false
dropped_item = nil
cigarette:update()
end

I keep getting “attempt to index global ‘whatever’ (a nil value)” errors, anyone know whats fucked up with my code?

Don’t post a “I got an error like this” post. Either post the full error or don’t post at all.

FATAL ERROR

[error]Expression : fatal error
[error]Function : CScriptEngine::lua_error
[error]File : E:\stalker\sources runk\xr_3da\xrGame\script_engine.cpp
[error]Line : 73
[error]Description : <no expression>
[error]Arguments : LUA error: …w of chernobyl\gamedata\scripts\smp_additions.script:174: attempt to index global ‘ciganim’ (a nil value)

You didn’t post the whole code but I can see you’re missing 2 ifs at these lines :
id not alife():object(dropped_item) then
string.find(obj:section, “cigarettepack_s25”) then

And you have an extra end at the last line.

Hurr.

Even though this is the Lua scripting forum, it’s a subforum of Garry’s Mod. I’m sure that game you’re making this for has it’s own help forum.