Raised This Month: $ Target: $400
 0% 

how?: if a float=0.0 ..then set float=1.0


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
cs1.7
Senior Member
Join Date: Oct 2008
Old 06-28-2010 , 15:27   Re: how?: if a float=0.0 ..then set float=1.0
Reply With Quote #1

thx..

well if g_AlivePlayers = 0 ..then the outcome of the formula is 0

will your method work then?


edit:

another question:

if variable is >30.0 --> set it to 30.0
if it is <15.0 -->set it to 15.0

how do i create such a code most efficiently? Can i create this via one if sentence?

here i need two if conditions to achieve my goal:
PHP Code:
    if(variableX 30.0)
    {
        
variableX  30.0;
    }
    else
    {
        
variableX  MAXm 400.0;
    } 
    
    if(
variableX  15.0)
    {
        
variableX  15.0;
    }
    else
    {
        
variableX  MAXm 400.0;
    } 


__________________
_____________
/_____\
[° ||| °]
./..............\▓

Last edited by cs1.7; 06-28-2010 at 17:23.
cs1.7 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-28-2010 , 18:36   Re: how?: if a float=0.0 ..then set float=1.0
Reply With Quote #2

Quote:
Originally Posted by cs1.7 View Post
thx..

well if g_AlivePlayers = 0 ..then the outcome of the formula is 0
Dividing by zero will result in an error.

Quote:
Originally Posted by cs1.7 View Post
edit:

another question:

if variable is >30.0 --> set it to 30.0
if it is <15.0 -->set it to 15.0

how do i create such a code most efficiently? Can i create this via one if sentence?
Code:
new Float:variable
variable = floatclamp(variable, 15.0, 30.0)
Quote:
Originally Posted by cs1.7 View Post
here i need two if conditions to achieve my goal:
PHP Code:
    if(variableX 30.0)
    {
        
variableX  30.0;
    }
    else
    {
        
variableX  MAXm 400.0;
    } 
    
    if(
variableX  15.0)
    {
        
variableX  15.0;
    }
    else
    {
        
variableX  MAXm 400.0;
    } 
I don't understand this code.
__________________
fysiks is offline
cs1.7
Senior Member
Join Date: Oct 2008
Old 06-28-2010 , 19:11   Re: how?: if a float=0.0 ..then set float=1.0
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
Dividing by zero will result in an error.
hmm.. it didnt. the formula returned a value of 0 if aliveplayers were 0.
Quote:
Originally Posted by fysiks View Post
I don't understand this code.
how can the below code made more efficient?
PHP Code:
    new FloatvariableX  MAXm 400;
    
    if (
variableX  30.0
    {
        
variableX  30.0;
    }
    
    if (
variableX  15.0)
    {
        
variableX  15.0;
    } 
__________________
_____________
/_____\
[° ||| °]
./..............\▓
cs1.7 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-28-2010 , 20:34   Re: how?: if a float=0.0 ..then set float=1.0
Reply With Quote #4

Code:
variableX = floatclamp( MAXm/400.0, 15.0, 30.0 )
__________________
fysiks is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:51.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode