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 / Health bar and equation not working

Author
Message
tonycrew
14
Years of Service
User Offline
Joined: 8th Jan 2010
Location:
Posted: 9th Mar 2010 01:15
Hi i have some code for a health/exp bar, i've tried it loads of ways but it doesn't work when adding the equation.

Tried this way


Tried with this line changed




But it works on a calculator and adds up to 3 but in our program when we just try + 3 instead of the sum, It works.

but this way won't or does'nt seem to add anything.

Basicaly it's taking 492 + (150 / 250 * 5) which should be 495,

Thanks for any help...

FPS Creator Updated 116,Vista 32Bit UpTo Date, nVidea 8500 1Gig Graphics Card, 4 Gig DDR2 Ram, Intel Duel Core 3GHZ CPU
tonycrew
14
Years of Service
User Offline
Joined: 8th Jan 2010
Location:
Posted: 9th Mar 2010 01:22
Also tried it this way but to no avail...



FPS Creator Updated 116,Vista 32Bit UpTo Date, nVidea 8500 1Gig Graphics Card, 4 Gig DDR2 Ram, Intel Duel Core 3GHZ CPU
tonycrew
14
Years of Service
User Offline
Joined: 8th Jan 2010
Location:
Posted: 9th Mar 2010 01:37
I just noticed as i ran it again in the output i get error



FPS Creator Updated 116,Vista 32Bit UpTo Date, nVidea 8500 1Gig Graphics Card, 4 Gig DDR2 Ram, Intel Duel Core 3GHZ CPU
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 9th Mar 2010 04:14
This is Dark Basic - NOT Delphi. '//' is not used as a comment.

Use Rem (or '`') - and even then, if it's on the same line as something else, don't forget the ':'.

TDK

Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 9th Mar 2010 04:18
? It is, try this:


the problem is the difference between floats and integers, search it, 'tis important!


TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 9th Mar 2010 04:49 Edited at: 9th Mar 2010 04:53
That's why I said:

Quote: "and even then, if it's on the same line as something else, don't forget the ':'."


print "hi" //print hi

is not a legitimate BASIC line, whereas

print "hi": //print hi

would be (assuming the continued use of //).

And just to clarify: By 'not a legitimate line', I don't mean 'does not work'.

Yes, // works, but it's not in any of the help files I have so as an undocumented feature, it shouldn't be relied on to work in future versions.

Never-the-less, the line ends with the last quotation mark of the "hi" so anything that follows, should be separated by a colon.

Quote: "search it, 'tis important"


Indeed it is, but if I did search, I would probably find my own tutorials on the subject, so I'll pass on that.

I didn't actually say that was the cause of his problem - just pointing something out.

TDK

tonycrew
14
Years of Service
User Offline
Joined: 8th Jan 2010
Location:
Posted: 9th Mar 2010 14:08
Ok thanks for the format info...





Got it working now as FLOAT, i tired FLOAT before but it didn't work as they all have to be FLOAT,

FPS Creator Updated 116,Vista 32Bit UpTo Date, nVidea 8500 1Gig Graphics Card, 4 Gig DDR2 Ram, Intel Duel Core 3GHZ CPU
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 10th Mar 2010 04:40
Quote: "
Indeed it is, but if I did search, I would probably find my own tutorials on the subject, so I'll pass on that. "


Sorry, that was directed at tonycrew . I know that TDK isn't DBPro-illiterate

Tonycrew, look up a tutorial on floats. Basically, integers are positive or negative real numbers with no decimals after them. Meaning -1532,52,0, and 53452 are integers, but 124.2345 is not.

Therefore, 150 and 250 are evaluated to be integers. we know that 150/240=.6, but since the input is all integers, the output is an integer, basically, 150/250 evaluates to 0 (drops the decimal place, "rounds down").

150/250.0 or 150.0/250 or 150.0/250.0 all evaluate to .6, but still, if you say

n as integer
n=.6

then n will be equal to zero (because n is an integer, the decimal .6 is dropped)

Look up a tutorial for more information. There are things called floating point innacuracies (IE if you said n#=3.1415926535, n# would not be *exactly* that number), which are also very important.


Teh Stone
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 10th Mar 2010 23:42
surely if it gets a decimal when it is declared as an int and it rounds the number 0.6 would be rounded to one and not zero

Sorry if I'm wrong I haven't read helpfules about it but thats just wuat maths lessons tell me
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 10th Mar 2010 23:49

nope.


Teh Stone
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 10th Mar 2010 23:58
Sorry my bad that still seems strange thoo
tonycrew
14
Years of Service
User Offline
Joined: 8th Jan 2010
Location:
Posted: 11th Mar 2010 00:16
Thanks for the help, i did c++ at college like 12 years ago, and i forgot so much, i know this language is a bit different, but i remember about floats etc, i just forgot. but at least its all fixed now so thanks

FPS Creator Updated 116,Vista 32Bit UpTo Date, nVidea 8500 1Gig Graphics Card, 4 Gig DDR2 Ram, Intel Duel Core 3GHZ CPU
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 11th Mar 2010 11:19
np

Quote: "Sorry my bad that still seems strange thoo "


It cuts down on processing time. To round a number, you would have to calculate the decimal places and then figure out whether to round up or down. So instead of calculating the decimal places then going through some other process, only the integer part is calculated.


TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 11th Mar 2010 12:59
Quote: "Sorry my bad that still seems strange thoo"


You are confusing variable 'casting' with rounding.

Casting floats into integers is like using the Int() function, which takes the integer (whole number part) part of a float (decimal number) and discards the part after the decimal point (the mantissa).

So, as Neuro Fuzzy demonstrated, .999 is the same as 0.999 so casting it into an integer variable loses the '999' bit resulting in 0.

To round numbers down and up, you would use the Floor() and Ceil() functions.

TDK

Login to post a reply

Server time is: 2024-11-24 20:46:35
Your offset time is: 2024-11-24 20:46:35