Jump to content

Question - Maths


manve1

Recommended Posts

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

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

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
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 by Guest
Link to comment

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 by Guest
Link to comment
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
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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...