Img:get() single value?

This might be a simple one and not terribly essential, but I keep running into it every now and then and I’m not code-savy enough to work it out. I’m only interested in a single value from img:get(x,y), so I can do an inline call to get only the value I want (r,g,b OR a), instead of defining all four like r,g,b,a = img:get(x,y) and then using only one of them.

I’ve been trying stuff like:
img:get(x,y).alpha -- nope img:get(x,y).a -- nothing img:get(x,y).w -- nada img:get(x,y)[4] -- no

My feeble attempt at code introspection was limited to math.type( img:get(x,y) ) but that just says integer. I looked through the help and forums but eventually resorted to starting a new topic as you may have noticed. :wink:

Many thanks!

I can get it to work inline by putting it in a color, but I bet there’s a more direct way?

color( img:get(x,y) ).a -- meh

Yes, you can, only need to write like below:

To get alpha:

_ , _ , _ , a = img:get(x,y)

To get red and alpha:

r , _ , _ , a = img:get(x,y)

For readability, I like @Kirl 's method, color( img:get(x,y) ).a

I don’t have a problem with doing r,g,b,a=img:get(x,y) and just using what value I need. But if you want to get only one value, create a function and call that.

function setup()

function imgGet(t,x,y)
    local c={}
    return c[t]

Thanks guys, so I guess there’s no way to isolate a value directly from img:get…?

I’m curious why this is so, are they returned iteratively within one cycle or something?

Just curious though. As mentioned I’m not very code savy, but I have a fair bit of scripting experience (AS, JS). So often the lower lvl workings are not very obvious to me.

Anyway, thanks again for the alternatives!

It’s because img:get returns 4 separate values, rather than a single Codea color user object.