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 / Error with Types

Author
Message
Kieran
18
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 30th Jul 2008 09:20
I have my type declared like this

type stats
health as integer
maxhealth as integer
endtype

player as stats

player.health = 50
player.maxhealth = 100

when I try using this equation to get the % of the health bar to fill

box 1, 1, (player.health/player.maxhealth)*100, 5

the equation player.health/player.maxhealth*100 returns 0
this equation means 50/100*100 = 0 when 50/100*100 actually equals 50.

Can anyone answer what is wrong here?

by the way, the box works normally when I put in a normal integer
Kieran
18
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 30th Jul 2008 09:30
haha now I feel really dumb, I just realised health and maxhealth are integers so it can't return the decimal needed when it says player.health/player.maxhealth. It works now
calcyman
17
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 30th Jul 2008 11:33
(player.health*100)/player.maxhealth should work

The optomist's right, The pessimist's right.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 30th Jul 2008 18:44
actually, calcyman's method would be best as its all integer math and still gives you the same result, unless you need the percentage to the tenths precision.


Login to post a reply

Server time is: 2024-11-24 23:03:37
Your offset time is: 2024-11-24 23:03:37