Call entity without being in a function

Hi!

How can I call the entity (in init.lua) without being in a ENT function ?




function ENT:Initialize()

  self:SetModel("models/props_lab/workspace001.mdl")
  self:PhysicsInit(SOLID_VPHYSICS)
  self:SetMoveType(MOVETYPE_VPHYSICS)
  self:SetSolid(SOLID_VPHYSICS)
  self:SetUseType( SIMPLE_USE )
  self:SetColor( Color( 133, 133, 133, 230 ) )

deskpos = self:GetPos()

end





net.Receive( "MakeEntity", function( len, ply )



local i = 1

  newspaperquantity = net.ReadInt(32)

  if ( newspaperquantity <= 0 ) then
  else

    while i <= newspaperquantity do



      local newspaper_ent = ents.Create( "newspaper" )
        if ( !IsValid( newspaper_ent ) ) then return end
          newspaper_ent:SetModel( "models/props_junk/garbage_newspaper001a.mdl" )
          newspaper_ent:SetPos( deskpos + Vector(0,-50,40))
          newspaper_ent:SetNPTitle( net.ReadString() )
          newspaper_ent:SetNPText( net.ReadString() )
          newspaper_ent:SetNPHeadline( net.ReadString() )
          newspaper_ent:Spawn()
          newspaper_ent:PhysWake()



          i = i + 1
     end

  end

end)


I can’t call “deskpos”, it says that’s a nil value.
I want the deskpos to be in the while loop.

Thanks.

(sorry for my poor grammar, english isn’t my native language)

Couple errors, you are making deskpos a global var. Instead make it self.deskpos = GetPos.

Second off, you need to write the deskpos when sending it in a net message.


net.Start("Blah")
    net.WriteVector(deskpos)
net.Send()

net.Recieve( function()
     local whatever = net.ReadVector()
end)

newspaper_ent:SetNWInt(“MyProp”,newspaper_ent)

And to call it:
local ent = geteyetraceandshit
local whichent:GetNWInt(“MyProp”)
print (whichent)