Entities calling server functions outside of their own init.lua

The example, I have a brush named “Box” in my map.

Init.lua (for the entity itself)
[lua]ENT.Base = “base_brush”
ENT.Type = “brush”

function ENT:StartTouch( ply )
if(ply:IsPlayer() and ply:IsValid()) then
enteredBox(ply)
end
end

function ENT:EndTouch( ply )
if(ply:IsPlayer() and ply:IsValid()) then
leftBox(ply)
end
end
[/lua]

Server’s Init.lua
[lua]
function enteredBox(ply)
ply:SetNWInt(“InBox”, 1)
umsg.Start(“enteredBox”,ply)
umsg.End()
end
[/lua]

error


attempt to call global 'enteredBox' (a nil value)

It seems that the entities Init.lua is unable to call functions outside the file so the “enteredBox(ply)” function cant even be seen.

Is there any way for the server’s init.lua functions to be called from an entities init.lua

everything works fine if it’s all inside the entities init.lua until I need to run checks on if theres a player inside it when they’re killed etc.

Umm the function name and the function name in error differs?

posted the wrong error, fixed.
Realised after posted, you must have ninjad before it was changed.

On the topic, this isn’t supposed to happen actually. Can you give more detal? Where is your “Server’s Init.lua” stored? I did a quick test and it worked.

\gamemodes\sandbox\gamemode

Yes I’m building on top of the sandbox gamemode, that shouldn’t cause anything like this though right.

The entity is in
\gamemodes\sandbox\entities\entities\box

If you are editing sandbox you should create a new gamemode deriving from it. All original files will be replaced to their defaults everytime GMod starts. Or move your code to lua/autorun/