I have a bunch of colours where the alpha is changing lots - but not the rgb bit.
So, I’d like to store this rgb bit in a constant:
local WHITE = vmath.vector3(1, 1, 1)
Then, in the script, I set the alpha value separately:
gui.set_color(node, WHITE)
gui.set_alpha(node, alpha)
Now I wonder if this could be done in a one-liner:
gui.set_color(node, vmath.vector4(the constant bit, alpha))
In short: is it possible to store parts of a vector in a constant/a variable? So far, I haven’t found a way.
Thank you @Alex_8BitSkull!
I know the api of course - and can’t find anything in it to anwer my question. 
I was trying to link specifically to the gui.set_alpha function, which if I understand your problem would be a solution! It’s not an answer to the question you asked, but would solve your problem anyway (if alpha is the only thing you’re changing).
1 Like
Ah - cool. 
Sure, that is what do atm - set my rgb and in the next line set alpha. I am just curious if it is possible to, how shall I put this - construct a vector4 out of my vector3 that hold the rgb values and the alpha. Sheer curiosity.
I think I understand now. It can be done in a one-liner like this:
gui.set_color(node, vmath.vector4(WHITE.x, WHITE.y, WHITE.z, alpha))
I’m not aware of a cleaner way or a way that allows you to “convert” a vec3 to a vec4.
3 Likes
Ahh! Of course, how could I miss this.
Thank you Alex!
2 Likes
If this is the only thing you’re going to use it for, rather than making a new vector4 every time, you could just make your constant a vector4 and modify its alpha value every time. To make it a one-liner, well, you put it into a function!
local WHITE = vmath.vector4(1, 1, 1, 1)
local function set_color(node, color, alpha)
color.w = alpha or 1
gui.set_color(node, color)
end
3 Likes
Ahh - that is a cool solution too, a function. Missed that one too.
Thank you Ross!
2 Likes