Integer number from Lua calculation needed

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Message
Author
User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Integer number from Lua calculation needed

#11 Post by jph »

Ralph wrote: Tue Nov 22, 2022 12:23 pm In canvas you can use float values on a fill. So 0,0,0 is black and 1,1,1 is white. I'm not sure if it works on text, you can try, saves you some trouble.
neat ! :)
Joe. CISSP, MSc.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Integer number from Lua calculation needed

#12 Post by Keith Baxter »

jph wrote: Tue Nov 22, 2022 12:12 pm
Keith Baxter wrote: Tue Nov 22, 2022 11:25 am
Using math.floor( ) will create errors as values will be outside of 0..255 scope.

You can use var_cap() for this.
Keith
That should never be an issue as the 'brightness' multiplier per colour would presumably be <= 1
That isn't a problem.
Hi,

Sorry that is incorrect. He is looking for values 0 to 255. This could be for brightness on a color 8 digit hex or the changing of the color hex pair.
The 4th pair is opacity.

AM uses opacity() but that is not precise to actual color hex. Using 8 digit hex gives exact control on all R,G,B and opacity.

I think the OP wants, is to control opacity of instruments/panels using color hex codes from a decimal 0 ->1 dataref

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Integer number from Lua calculation needed

#13 Post by Keith Baxter »

Ralph wrote: Tue Nov 22, 2022 12:23 pm In canvas you can use float values on a fill. So 0,0,0 is black and 1,1,1 is white. I'm not sure if it works on text, you can try, saves you some trouble.
Hi,
Try 0,0,0,1 or 1,1,1,0 also just for fun 0,0,0,0.5 :mrgreen:

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Ralph
Posts: 7880
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Integer number from Lua calculation needed

#14 Post by Ralph »

That should in theory work as well.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Integer number from Lua calculation needed

#15 Post by Keith Baxter »

Ralph wrote: Tue Nov 22, 2022 12:42 pm That should in theory work as well.
Hi,

Yes and color hex code also works in all AM functions. Whilst 8 digit color hex code is not mentioned in the API like other many features it is a very useful feature.


Normal opaque black hex- “#000000”
Fully transparent – “#00000000”
Fully opaque – “#000000FF”
50% transparent – “#0000007F”

Keith
Last edited by Keith Baxter on Tue Nov 22, 2022 1:45 pm, edited 1 time in total.
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Integer number from Lua calculation needed

#16 Post by jph »

Keith Baxter wrote: Tue Nov 22, 2022 12:32 pm
jph wrote: Tue Nov 22, 2022 12:12 pm
Keith Baxter wrote: Tue Nov 22, 2022 11:25 am
Using math.floor( ) will create errors as values will be outside of 0..255 scope.

You can use var_cap() for this.
Keith
That should never be an issue as the 'brightness' multiplier per colour would presumably be <= 1
That isn't a problem.
Hi,

Sorry that is incorrect. He is looking for values 0 to 255. This could be for brightness on a color 8 digit hex or the changing of the color hex pair.
The 4th pair is opacity.

AM uses opacity() but that is not precise to actual color hex. Using 8 digit hex gives exact control on all R,G,B and opacity.

I think the OP wants, is to control opacity of instruments/panels using color hex codes from a decimal 0 ->1 dataref

Keith
Yes, therefore if you multiply a value of 255 or less by 1 or less then you will never get a value of > 255 :roll:
The <= 1 part is obviously not an integer..... hence it is NOT
Using math.floor( ) will create errors as values will be outside of 0..255 scope.
(the above is incorrect in this case) which is exactly what I said. tum te tum te tum. ;)
Joe. CISSP, MSc.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Integer number from Lua calculation needed

#17 Post by Keith Baxter »

Joe,

I fully understand the issue and know the resolve. I have no appetite to argue with you.

Keith

EDIT: @Corjan Any chance of a hex converter ?
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Integer number from Lua calculation needed

#18 Post by jph »

Not arguing old chap, just pointing out the error of your ways. :)

Which way do you want to convert hex ?
hex to dec

You can use tonumber already as in

Code: Select all

x =(tonumber("0xFF"))
print (x)
-- or
print(tonumber("0xFF"))
-- or
y =(tonumber("FF",16))
print (y)
--or 
print(tonumber("FF",16))
Joe. CISSP, MSc.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Integer number from Lua calculation needed

#19 Post by Keith Baxter »

Hi,

The crux of the OP question is to create a Hex value ( dataref or some other source) from a decimal 0 ->1 value without a nil returned.

Just to be clear for all hex color is RGBA

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Integer number from Lua calculation needed

#20 Post by Sling »

Keith Baxter wrote: Tue Nov 22, 2022 1:56 pm Hi,

The crux of the OP question is to create a Hex value ( dataref or some other source) from a decimal 0 ->1 value without a nil returned.

Keith
The issue was not stopping a nil but rather a way to stop the calculation that feeds into the hex conversion from returning a float because the conversion only accepts an integer.
Keith Baxter wrote: Tue Nov 22, 2022 7:45 am math.floor() and var_round() or var_format() produce the same. math.cell() is different.
Additionally math.floor() and var_round() or var_format() do not produce the same. Try 4.7 in them and you’ll see the difference. Just wanted to clear that up so someone doesn’t read that later and think you’ll get the same result from those.

Post Reply