manve1 Posted January 16, 2013 Share Posted January 16, 2013 Is there a function which gets numbers between 60 and 100 (( not math.random )) which would get each second (( using timer ofc )) and would change a label color if number changes, i don't want the math.random as it generates number randomly, i want it to go down from 100 to 60 And if it is 90 to 100 (( 91, 92, 93 .. ect .. )) it will be one color, if its from 60 to 70 ( 61, 62, 63 .. ect )) it will be another color Link to comment
Castillo Posted January 16, 2013 Share Posted January 16, 2013 variable = 100 variable = ( variable > 59 and variable - 1 ) You'll have to execute it on a timer. Link to comment
manve1 Posted January 16, 2013 Author Share Posted January 16, 2013 I came up with this after ur post, but label is still white and it say's ''100 %'' on the label setTimer( function( ) variable = 100 variable = ( variable > 59 and variable - 1 ) if ( guiGetText( label ) == ''.. variable ..' %' ) then guiLabelSetColor( label, 0, 255, 0 ) end end, 50, 0 ) Link to comment
novo Posted January 16, 2013 Share Posted January 16, 2013 You're re-setting value to 100. Move the variable out the function to load it once. variable = 100 setTimer( function( ) variable = ( variable > 59 and variable - 1 ) if ( guiGetText( label ) == variable ..' %' ) then guiLabelSetColor( label, 0, 255, 0 ) end end, 50, 0 ) Link to comment
manve1 Posted January 16, 2013 Author Share Posted January 16, 2013 it compared number with boolean when i done what you (( novo )) said Link to comment
Castillo Posted January 16, 2013 Share Posted January 16, 2013 Does "label" exist? post your full code. Link to comment
manve1 Posted January 16, 2013 Author Share Posted January 16, 2013 (edited) label = guiCreateLabel( 0.855, 0.235, 0.1, 0.1, '0 %', true ) guiSetText( label, 100 ..' %' ) variable = 100 setTimer( function( ) variable = ( variable > 59 and variable - 1 ) if ( guiGetText( label ) == variable ..' %' ) then guiLabelSetColor( label, 0, 255, 0 ) end end, 50, 0 ) Edited January 16, 2013 by Guest Link to comment
3NAD Posted January 16, 2013 Share Posted January 16, 2013 (edited) Try it and tell me the Results. label = guiCreateLabel ( 0.855, 0.235, 0.1, 0.1, '0 %', true ) variable = 60 setTimer ( function ( ) variable = variable + 1 if variable > 60 then guiLabelSetColor ( label, 0, 255, 0 ) elseif variable > 70 then guiLabelSetColor ( label, 255, 0, 0 ) elseif variable > 80 then guiLabelSetColor ( label, 255, 255, 0 ) elseif variable > 90 then guiLabelSetColor ( label, 0, 0, 255 ) elseif variable > 100 then guiLabelSetColor ( label, 0, 255, 255 ) variable = 60 end end , 50, 0 ) Edited January 16, 2013 by Guest Link to comment
manve1 Posted January 16, 2013 Author Share Posted January 16, 2013 problem, when its 50 its green Link to comment
Castillo Posted January 16, 2013 Share Posted January 16, 2013 percent = 100 label = guiCreateLabel( 0.855, 0.235, 0.1, 0.1, percent ..' %', true ) setTimer ( function ( ) if ( percent > 59 ) then percent = ( percent - 1 ) guiSetText ( label, percent ..' %' ) if ( guiGetText ( label ) == percent ..' %' ) then guiLabelSetColor ( label, 0, 255, 0 ) end end end ,50, 0 ) Link to comment
manve1 Posted January 16, 2013 Author Share Posted January 16, 2013 it shouldn't go down then stop when its 59%, it should change color when its 0 to 30 <= red, 31 to 59 <= orange, 60 to 100 <= green @3Nad your edited script didn't work too Link to comment
Castillo Posted January 16, 2013 Share Posted January 16, 2013 percent = 100 label = guiCreateLabel( 0.855, 0.235, 0.1, 0.1, percent ..' %', true ) setTimer ( function ( ) if ( percent > 0 ) then percent = ( percent - 1 ) guiSetText ( label, percent ..' %' ) local color = ( percent < 30 and { 255, 0, 0 } or percent < 60 and { 255, 50, 0 } or percent >= 60 and { 0, 255, 0 } ) guiLabelSetColor ( label, unpack ( color ) ) end end ,50, 0 ) Works ( tested ). Link to comment
manve1 Posted January 16, 2013 Author Share Posted January 16, 2013 This worked, but there isn't orange color, i tested few times, and i couldn't see orange color Link to comment
Castillo Posted January 16, 2013 Share Posted January 16, 2013 I did, but since the orange I set is really similar to red, you can confuse. Change this: 255, 50, 0 To another orange code, like this: 255, 100, 0 Link to comment
manve1 Posted January 16, 2013 Author Share Posted January 16, 2013 after changing timer time, it somehow just ruins the 100 number and becomes 1000 Link to comment
Castillo Posted January 16, 2013 Share Posted January 16, 2013 I don't understand what do you mean. Link to comment
3NAD Posted January 16, 2013 Share Posted January 16, 2013 Did you mean, Like this. label = guiCreateLabel ( 0.855, 0.235, 0.1, 0.1, '0 %', true ) variable = 59 setTimer ( function ( ) variable = variable + 1 guiSetText ( label, variable ..' %' ) if ( variable >= 100 ) then guiLabelSetColor ( label, 0, 255, 255 ) variable = 59 elseif ( variable >= 90 ) then guiLabelSetColor ( label, 0, 0, 255 ) elseif ( variable >= 80 ) then guiLabelSetColor ( label, 255, 255, 0 ) elseif ( variable >= 70 ) then guiLabelSetColor ( label, 255, 0, 0 ) elseif ( variable >= 60 ) then guiLabelSetColor ( label, 0, 255, 0 ) end end , 500, 0 ) Link to comment
manve1 Posted January 17, 2013 Author Share Posted January 17, 2013 Thank you guys for the information how to do it, but I didn't mean like that 3NAD, but i re-made yours to make it work as i wanted and added for more things in there so i can't post the script as it now has more lines then that Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now