Update position of entity in PlayURL.

Hello fellow lua developers,

I’ve been busy for some time to get the position to update and give it to the sound.PlayURL. The main problem I have is that it does call it correctly but the sound doesn’t move with the entity when the entity moves.

cl_init.lua



function ENT:Think()
     entpos = self:GetPos()
end
function PlayRadio (station, entpos)
		
			sound.PlayURL ( "http://yp.shoutcast.com/sbin/tunein-station.pls?id=7540&play_status=1" , "play 3d", function( station ) 
				if ( IsValid( station ) ) then
					station:SetPos( entpos ) 
					station:Play()
					station:SetVolume( 1 )
				else 
					LocalPlayer():ChatPrint( "Something is wrong with the channel." )
				end
			end)
	end


As an error I get that entpos is no Vector but an string but how is it an string. When I print entpos then entpos is an vector.

I am totally lost, and sadly no idea on how to fix this. Hopefully someone can help me.



local g_Station
function ENT:Think()
	g_Station:SetPos( self:GetPos() ) 
end
function PlayRadio (station, entpos)
		
			sound.PlayURL ( "http://yp.shoutcast.com/sbin/tunein-station.pls?id=7540&play_status=1" , "play 3d", function( station ) 
				if ( IsValid( station ) ) then
					station:Play()
					station:SetVolume( 1 )
					g_Station = station

				else
					LocalPlayer():ChatPrint( "Something is wrong with the channel." )
				end
			end)
	end

[editline]3rd February 2014[/editline]

You were setting the position only once, but refreshing the variable all the time.

When I try that, I get an error popping up:

I think the problem is


local g_Station

since it isn’t defined? Also, where does the g_ stand for actually?


function ENT:Think()
     if ( IsValid( g_Station ) ) then
        g_Station:SetPos( self:GetPos() )
    end
end

g_ is a convenient way to separate global variables ( even though it isn’t global in this case ) from other variables.

Working now, thanks a bunch for the quick respond. Solved.