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 / Real and Integer Variables....help me

Author
Message
CornStalks
20
Years of Service
User Offline
Joined: 12th Feb 2004
Location: Utah
Posted: 18th Apr 2005 09:47
Okay, so I want to have a variable store the value of .001 but whenever I try, it just sets it to 0. It seems that all the variables I use are Integer types, but I want a Real variable to store deicemals. How do I make a Real variable?

dang im hot...
Antidote
19
Years of Service
User Offline
Joined: 18th Mar 2005
Location: San Francisco, CA
Posted: 18th Apr 2005 10:00
lets say you have the variable "number"

so to make it a real you put a pound sign behind it like this

number#

to make it a string (a variable that can hold anything) write it with a dollar sign after it like this

number$

note: string values must have quotation marks around them like this

word$="Hello"

I have know idea what sflm stands for
Ace Of Spades
19
Years of Service
User Offline
Joined: 6th Mar 2005
Location: Across the ocean
Posted: 18th Apr 2005 10:03


CornStalks
20
Years of Service
User Offline
Joined: 12th Feb 2004
Location: Utah
Posted: 18th Apr 2005 10:05
thanks a ton

dang im hot...
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 18th Apr 2005 10:09
you can cast the float data type as follows

variablename as FLOAT

then in calcualtions use the # after the variable name to declare a real number variable

eg's.

weight as float
----
weight#=playerswght#+itemwght#
----
print weight#
----

myfloat#=.09
newfloat#= .09 * .2
print newfloat#
----

Hope that helps

~zen


the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 18th Apr 2005 10:27
If you use AS FLOAT you don't need to use #.
If you do you end up with two variables.
weight
weight#

Quote: "this is not a quote"
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 18th Apr 2005 10:51
thanks the_winch for clearing that up, that's what I meant to type but I got ahead of myself.



~zen


CornStalks
20
Years of Service
User Offline
Joined: 12th Feb 2004
Location: Utah
Posted: 20th Apr 2005 00:50 Edited at: 20th Apr 2005 00:50
lol cool thanks, just one question though. Whenever I do something like speed#=speed#-.01 just to try and make it so it equals .09, it always ends up all weird, like .09165411254 and stuff like that. Why does it add all that stuff instead of it just going straight to .09?
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 20th Apr 2005 02:48
32 Melted Gummy Bears,
I haven't been around for a while, so I'm not sure if a new command has been introduced to address this. It's not really a bug. It's just that processors have left over "garbage" in them whe performing floating point math. C++ deals with this by haveing a set precision command. In this way if you want accuracy limeted to 2 decimal place you can set precision to 2 so that the erroneous remainder is discarde. I'm sure that someone has a function that automatically deals with this. for calculation purposes in games it shouldn't really be a problem.

I guess the problem can be when you want to display the value. If I remmember correctly I used one of two ways to deal with this issue.

1) strip out the decimal point and work the calcualtion with ints and then convert the in back to a float by multiplying by a negative power of 10 to set ehe deciaml point

2) when displaying the float convert the float to a string and cut parse or cut the string down to the accurate number of characters.

I am going from what I remember. Like I said someone surely has made a set precision on floats plugin.

~zen


Login to post a reply

Server time is: 2024-09-23 17:24:56
Your offset time is: 2024-09-23 17:24:56