[Resolved] alpha not working

Which is wrong?

myVariable.alpha = math.random (0.5, 1.0)
or
myVariable.alpha = math.random (50, 100)

tried both and i dont get a result…or maybe im not seeing it?

Please advise. Thank you! :smiley: [import]uid: 157993 topic_id: 30123 reply_id: 330123[/import]

Well, neither really. Alpha values are from 0.0 to 1.0 and looks like the math.random value is only going to give you a 0 or a 1 when using decimals. Without look into any other Lua math functions you could do the below.
[lua]myVariable.alpha = math.random(50, 100) / 100[/lua]

That will give you a valid decimal value for the alpha setting. [import]uid: 147305 topic_id: 30123 reply_id: 120581[/import]

oh! I see…can you tell me what the /100 at the end is for? Thank you! [import]uid: 157993 topic_id: 30123 reply_id: 120583[/import]

the math.random(50,100) is going to give you a random number between 50-100(which im sure you realize). Since we want a decimal value you divide it by 100. So if the math.random gives 87 then when we do /100 it gives .87. [import]uid: 147305 topic_id: 30123 reply_id: 120586[/import]

Oh! Hmmm, I see. Ok well i appreciate you explaining that. Thanks a lot!

Cheers! ;D [import]uid: 157993 topic_id: 30123 reply_id: 120617[/import]

Well, neither really. Alpha values are from 0.0 to 1.0 and looks like the math.random value is only going to give you a 0 or a 1 when using decimals. Without look into any other Lua math functions you could do the below.
[lua]myVariable.alpha = math.random(50, 100) / 100[/lua]

That will give you a valid decimal value for the alpha setting. [import]uid: 147305 topic_id: 30123 reply_id: 120581[/import]

oh! I see…can you tell me what the /100 at the end is for? Thank you! [import]uid: 157993 topic_id: 30123 reply_id: 120583[/import]

the math.random(50,100) is going to give you a random number between 50-100(which im sure you realize). Since we want a decimal value you divide it by 100. So if the math.random gives 87 then when we do /100 it gives .87. [import]uid: 147305 topic_id: 30123 reply_id: 120586[/import]

Oh! Hmmm, I see. Ok well i appreciate you explaining that. Thanks a lot!

Cheers! ;D [import]uid: 157993 topic_id: 30123 reply_id: 120617[/import]