Color doesn't always populate correctly

I’m working on a mod that changes a player’s color for a short time, and then changes it back. I’m trying to learn LUA for gmod.

I start by creating an array of all players and props on the map.
I then store the color of each player/prop
The issue is this, I populate a color from an entity using the following code:



local c = v:GetColor()
local r,g,b,a = c.r, c.g, c.b, c.a
print("RGBA: " .. r .. g .. b .. a )


That color SHOULD be 255, 255, 255, 255 because none of the colors have been modified yet. The problem I have is I keep getting
255, 0, 255, 255 in that print line. BUT sometimes I DO get 255, 255, 255, 255. What the heck is going on here?

Wouldn’t all props/players have their color set to 255,255,255,255 by default?

EDIT: Here’s what the console spits out:



RGBA: 2550255255
RGBA: 2550255255
RGBA: 255255255255
RGBA: 2550255255
RGBA: 2550255255
RGBA: 2550255255
RGBA: 2550255255



Either something on your client/server is overriding the color and the entity has this color given by map. Add the “v” to the print and post new output.

Apparently I don’t even know how to use GetName?

attempt to call method ‘GetName’ (a nil value)



print("RGBA: " .. r .. g .. b .. a )
print( "V = " .. v:GetName() )


GetClass



RGBA: 2550255255
V = class C_BaseFlex
RGBA: 2550255255
V = class C_BaseFlex
RGBA: 2550255255
V = class C_BaseFlex
RGBA: 2550255255
V = class C_BaseFlex
RGBA: 255255255255
V = player
RGBA: 2550255255
V = viewmodel
RGBA: 2550255255
V = gmod_hands
RGBA: 2550255255
V = weapon_crowbar
RGBA: 2550255255
V = weapon_pistol
RGBA: 2550255255
V = weapon_smg1
RGBA: 2550255255
V = weapon_frag
RGBA: 2550255255
V = weapon_physcannon
RGBA: 2550255255
V = weapon_crossbow
RGBA: 2550255255
V = weapon_shotgun
RGBA: 2550255255
V = weapon_357
RGBA: 2550255255
V = weapon_rpg
RGBA: 2550255255
V = weapon_ar2
RGBA: 2550255255
V = gmod_tool
RGBA: 2550255255
V = gmod_camera
RGBA: 2550255255
V = weapon_physgun



Hmm… and you are absolutely sure no other addon you have causes this?

Pretty sure. I will try a vanilla install of gmod to be certain. I’ve removed all of my addons, but there still could be some scripts lurking in my lua folder.

[editline]11th July 2014[/editline]

It isn’t related to how i’m getting the ent list, is it?



for k,v in pairs( ents.GetAll() ) do

		if string.sub( (v:GetModel() or "" ), -3) == "mdl" then 

			local c = v:GetColor()
			local r,g,b,a = c.r, c.g, c.b, c.a
			print("RGBA: " .. r .. g .. b .. a )
			print( "V = " .. v:GetClass() )



I’ve noticed an issue with Color too. Recently, when connecting to the server the admin color is seen as white when it is supposed to be blue. Upon auto-refresh it shows properly.

This is an issue I had when making it a meta-table, so it may not be loading early enough to catch all of the Colors being added…