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 , 14:31   how?: if a float=0.0 ..then set float=1.0
Reply With Quote #1

hi

how can i force "floatX" to be 1.0 ..if has a value of 0.0?

this does not work:

PHP Code:
  new Float:floatX variableM 100 g_AlivePlayers;
  if(
floatX 0.0)
  {
    
floatX 1.0;
  } 
__________________
_____________
/_____\
[° ||| °]
./..............\▓
cs1.7 is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 06-28-2010 , 14:39   Re: how?: if a float=0.0 ..then set float=1.0
Reply With Quote #2

= means set
== means "is equal to"
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
cs1.7
Senior Member
Join Date: Oct 2008
Old 06-28-2010 , 15:07   Re: how?: if a float=0.0 ..then set float=1.0
Reply With Quote #3

actually that can be considered as a typo.

i do have :

PHP Code:
  if(floatX == 0.0)
  {
    
floatX 1.0;
  } 
and it's not working.
__________________
_____________
/_____\
[° ||| °]
./..............\▓
cs1.7 is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 06-28-2010 , 14:57   Re: how?: if a float=0.0 ..then set float=1.0
Reply With Quote #4

PHP Code:
new Float:floatX variableM 100 g_AlivePlayers;
  if(
floatX == 0.0)
  {
    
floatX 1.0;
  } 
__________________
Quote:
#define true ((rand() % 2)? true: false) //Happy debugging suckers
mottzi is offline
Send a message via MSN to mottzi
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 06-28-2010 , 15:16   Re: how?: if a float=0.0 ..then set float=1.0
Reply With Quote #5

Floats are not like integers. Results of formulas rarely equal 0.0, so use something like this:
PHP Code:
#define FLOAT_ZERO 0.0001 //anything lower than this is considered 0.0
if(-FLOAT_ZERO <= floatX <= FLOAT_ZERO)
{
    
floatX 1.0;

__________________
Impossible is Nothing
Sylwester is offline
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 #6

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

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 #8

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 #9

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