Jump to content

Question - Maths


manve1

Recommended Posts

Posted

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

Posted

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 
) 

Posted

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 
) 
  

Posted (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 by Guest
Posted (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 by Guest
Posted
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 
) 

Posted

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

Posted
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 ).

Posted

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

Posted

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 ) 

Posted

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

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...