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.

DarkBASIC Professional Discussion / Simple percentage calculator not working as expected

Author
Message
Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 16th Oct 2012 08:18 Edited at: 16th Oct 2012 08:26
Hi all,

I have run into an annoying problem and for the life of me cannot work out why my program is behaving the way it is.

I have written a routine that is supposed to fade objects out as they approach a specified distance from the player.

The alpha value is determined by a percentage value derived from the objects distance vs the cutoff distance.

the simple formula for a percentage should be 100/maxscale*value right?

my program is not behaving this way and no matter how I tweak it I just get a value of 100.

I have gone over and over it, but it seems I cannot see the solution yet.


here is a simplified program outlining the issue.
The lines of code in question are between the commented XXXXXXXX lines.





Can anyone see where I am slipping up?

Thankyou.

kezzla

ps: I have tried the formula with float variables and gotten the same result.

Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 16th Oct 2012 08:50
Quote: "the simple formula for a percentage should be 100/maxscale*value right?"

no, it should be like this: 100.0/maxscale*value. Maxscale has to be a float variable too

Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 16th Oct 2012 09:13
SWEET!

You are a legend Brendy boy that did the trick.

In my float version of that code I thought that as the receiving variable was a float then I could put an int into the formula and it would converted.

I also thought that behind the scenes the values would be floats until stored as an int.

A little wiser now.

Thanks for your help brendy boy, that was driving me nuts.



Login to post a reply

Server time is: 2026-07-07 21:32:31
Your offset time is: 2026-07-07 21:32:31