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.
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()
r=imgGet("r",x,y)
a=imgGet("a",x,y)
end
function imgGet(t,x,y)
local c={}
c["r"],c["g"],c["b"],c["a"]=img:get(x,y)
return c[t]
end
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.