help with floating variables
Blitz3D Forums/Blitz3D Beginners Area/help with floating variables Your dividing two INT's. You won't get a float result like that. Change the enemys_hit to a float, and it will work :o)
I've noticed that you have to that even when doing a fraction like 1/2, which would return a 0. You have to put 1.0/2 or 1/2.0 or 1.0/2.0
Hi
you have to force one or another (enemys_hit or bullets_shot ) to be float:
enemys_hit = 1
bullets_shot = 2
accuracy1# = Float(enemys_hit)/bullets_shot
accuracy2# = enemys_hit/Float(bullets_shot)
Print accuracy1+", "+accuracy2
WaitKey
enemys_hit / bullets_shot : will give you 0.0 because both are integers and the quotient is integer 0, accuracy is a float, and print shows you as 0.0
accuracy# = float(enemys_hit / bullets_shot) will give you the same 0.0 result, because blitz firs do the division, resulting an integer 0, and then converts it to float: 0.0
when mixing integers and floats we all have to take care!
best regards
Juan
edit: two were writing at the time I do the post!, so I came third
you have to force one or another (enemys_hit or bullets_shot ) to be float:
enemys_hit = 1
bullets_shot = 2
accuracy1# = Float(enemys_hit)/bullets_shot
accuracy2# = enemys_hit/Float(bullets_shot)
Print accuracy1+", "+accuracy2
WaitKey
enemys_hit / bullets_shot : will give you 0.0 because both are integers and the quotient is integer 0, accuracy is a float, and print shows you as 0.0
accuracy# = float(enemys_hit / bullets_shot) will give you the same 0.0 result, because blitz firs do the division, resulting an integer 0, and then converts it to float: 0.0
when mixing integers and floats we all have to take care!
best regards
Juan
edit: two were writing at the time I do the post!, so I came third
thanks, I get it now.