Lua SENT and AtmosGlobal Vars indexing nil ?

Hello fellows, I’m creating a Entity that works together with Atmos (the weather addon) and wiremod.

This entity gets the GlobalAtmos vars and outputs it to the Entity spawned for control with wiremod.

This is the code:



function ENT:Think()
    local hrs = AtmosTimeHours()
    WireLib.TriggerOutput( self, "GetHours", hrs)
end


The local vars get this functions:



function AtmosTimeHours()
    local hrs = AtmosGlobal:GetTime();
    local hours = math.floor( hrs );
    local minutes = ( hrs - hours ) * 60;
    if (hrs != nil) then
        return hours
    else
        return
    end
end


The code works, but it SPAMS console with this message:


[ERROR] lua/wire_atmos_base.lua:2: attempt to index global 'AtmosGlobal' (a nil value)  1. AtmosTimeHours - lua/wire_atmos_base.lua:2
   2. unknown - lua/entities/wire_atmos.lua:75


There’s a fix for it ? What I’m doing wrong ?

You’re (probably) running it on both the server and the client. Wrap the contents of your think function with if SERVER then … end

That works, thank you. Why it did that ?

Another problem I’m having with this entity code

I decalred that the prop spawned will be:


self:SetModel( "models/MaxOfS2D/cube_tool.mdl" )
	self:PhysicsInit(SOLID_VPHYSICS)
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid(SOLID_VPHYSICS)

	end
	local phys = self:GetPhysicsObject()
		if ( IsValid( phys ) ) then
			phys:Wake()
		end

but when I move the prop around with the physgun, the physgun beam stays in the start position of the prop.

Why ?

You’re creating the physics on both the server and the client. Wrap everything after SetModel ( and even that can be as well ) in the same type of block.

Unless you define these functions in a server-only file, the client will run them too - Initialize, Think, Use, etc.

Nevermind, it was the same error. Just added the “if ( CLIENT ) then return end” code and it fixed.

Thanks !