• How to properly use Vector:ToColor()?
    2 replies, posted
Hello again! I need to use the class Vector:ToColor(), however, when I use it, it gives this error... [ERROR] gamemodes/mygamemode/gamemode/init.lua:471: attempt to concatenate a table value   1. unknown - gamemodes/mygamemode/gamemode/init.lua:471 In init.lua: print("test for netbool: " .. ply:GetNWVector("color"):ToColor()) This is what I wrote that gives me an error. However, if I were to add a to string instead of :ToColor(), the vector prints out. print("test for netbool: " .. tostring(ply:GetNWVector("color"))) test for netbool: 0.562500 0.000000 0.000000, that's it printing out the vector value, which I need converted to a color value. If anyone could help, it would be greatly appreciated!
It's because you're trying to join a string to a vector. print("test for netbool: " .. ply:GetNWVector("color"):ToColor()) This is like doing this: print("test for netbool: " .. Vector( 1, 2, 3 )) You can't join a vector to a string. Try this: print("test for netbool") print(ply:GetNWVector("color"):ToColor())
Adding onto MPan1's suggestion, to make it even simpler just use the built-in tostring function: tostring(var) It pretty much converts between all variable types, even objects like Vector and Color in your case. print("test for netbool: "..tostring(ply:GetNWVector("color"):ToColor()))
Sorry, you need to Log In to post a reply to this thread.