Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / function doesn't accept float value

Author
Message
Kiaurutis
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location: Lithuania
Posted: 6th Aug 2011 17:53
I am trying to make some health bars in my game. Problem is that I can't pass float numbers to function that draws the bars. It receives only integer

This checks all the objects and asks other function to draw the bar:



This actually draws the health bar: defines the length and color of inner bar. I tried to use "as float" and "#" separately and both at once to set "value" as float but nothing helps. The program even started to crash so I separated calculation of value# into 2 steps: calculate 2 variables and divide them to get value#



The reason I want to have separate function to draw the bar is that there will be up to 5 classes of objects that will have their own FOR loop.

PS I use the same method to calculate value to be passed into drawing bars function and to write units info so calculation of hp and maxhp for vehicles is correct. As seen in the image function should get value 42/50=0.84 but it gets 0.000

Join The dark Side! We have cookies

Attachments

Login to view attachments
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 6th Aug 2011 19:04 Edited at: 6th Aug 2011 19:10
If Unit().Hp and Unit().MaxHp are integers then it'll cause a problem showing a float.

Really though things like hit points should always be whole numbers to make it easier to work with... in real life there is no such thing as being half-hit.

My way to do a health bar (I'm too lazy to modify this for Image Kit):


Kiaurutis
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location: Lithuania
Posted: 6th Aug 2011 22:45 Edited at: 6th Aug 2011 22:57
It is an RTS health bar, so I make many of them. If there would be only 1 then yes, I would use sprites. But I need to paste many of them, so images are the best IMO.

What you said about integers, its true, they are integers, but doesn't integer/integer give float? I thought there is a special function to divide integers to still have integer value. I think those functions in pascal was div and mod. I will try to change Unit.Hp into a float.

My game aims at integer type damage. Like in the game "desert rats vs africa corps". units have integer hp, integer armor and integer damage

[EDIT] Yes it works now. But maybe there is some way to make division of integers a float value?

Join The dark Side! We have cookies

Login to post a reply

Server time is: 2024-11-24 02:36:09
Your offset time is: 2024-11-24 02:36:09