I'm trying to reference an addon that I created which removes timers. However, it doesn't seem to be seeing the file. The file that I want to reference in lua/autorun/server. The file that is referencing it is located in lua/entities. I'm getting the following error:
[ERROR] lua/entities/ent_fullrestore/init.lua:25: attempt to call global 'removeServerTimers' (a nil value)
1. unknown - lua/entities/ent_fullrestore/init.lua:25
This is my code:
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
include("autorun/server/damage_system.lua")
function ENT:Initialize()
self:SetModel("models/items/healthkit.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:Wake()
end
end
function ENT:Use( activator )
local health = activator:Health()
removeServerTimers( activator )
activator:SetHealth( math.Clamp( ( health or 100 ) + 10, 0, 100 ) )
--activator:PrintMessage( HUD_PRINTTALK, "You drank a can of coca cola!" )
self:Remove()
end
Can you post the contents of the other file? (where the removeServerTimers function is supposedly defined?)
I posted a snippet
It's a local function.
Programming in Lua (<- about local and global stuff)
What's the point of including a file then? Should I just make a function global whenever I need to use it somewhere else then?
include - "Executes a Lua script."
Yes, you should just make a function global if you need to use it elsewhere, however, the best way to do this is to create a global table and add all your functions into that.
Example:
CUSTOMADDONFUNCS = {}
function CUSTOMADDONFUNCS.DoStuff()
end
Make the function unique or add it to a table which is unique - there are many options.
Sorry, you need to Log In to post a reply to this thread.