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 / Strange numbers

Author
Message
Conor B
19
Years of Service
User Offline
Joined: 10th May 2005
Location: Dublin, Ireland
Posted: 29th May 2007 23:47
Hi, I have searched the forums and found out about inacurate numbers, I have tried various things but amn't getting anywhere so I was wondering if someone could help.
A pic is attached with the result of this code:

if spacekey()=1 then shoot#=1
if shoot#=1 then move object 5,object position x(5)+2

text 0,20,str$(object position x(5))

Can somone please tell me why I am getting strange numbers and the letter "e" in the picture attached, thanks

Don't look behind you.

Attachments

Login to view attachments
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 30th May 2007 04:18 Edited at: 30th May 2007 04:19
shoot# is a float.

1 is an integer.

'e' is exponential - used when numbers are really huge, or really small.

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

See tutorial 5 and things will make a bit more sense...

TDK_Man

LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 30th May 2007 04:53
You are moving object 5 it's current x position+2, so if it's x position is 500, the next move will place it at 1002. The next move will place it at 2006 and so on. My guess is that you really only want to move it 2. It seems you are exponentially increasing the object's x position and hence, the
Quote: "strange numbers and the letter "e""
.

I don't see where shoot# is ever returned back to 0 in the code shown (perhaps it does and you just didn't show it). If you don't return it to 0, the code will keep moving object 5 by it's position +2 from the very first time you press the spacebar.

By the way, you are using the float 'shoot#' like an integer. If you need it to be a float, you should show it as 1.0. If you don't need it as a float, just take the # sign off and use it as an integer. You could just take the shoot# variable out of the mix completely and just move object 5 when the spacebar is pressed.
You could do it like this:



Hope this helps.

LB
Conor B
19
Years of Service
User Offline
Joined: 10th May 2005
Location: Dublin, Ireland
Posted: 30th May 2007 14:58
Well I tried all these things and it still doesnt work. The shoot# does go down to 0 after it has hit something or reached a certain distance. I need the shoot# because without it the bullet will only move while you are holding spacekey. There is also one more thing, when the numbers reach a certain distance it goes back to normal numbers with lots of decimal places but no letter, could someone tell me why, thanks.

Don't look behind you.
Conor B
19
Years of Service
User Offline
Joined: 10th May 2005
Location: Dublin, Ireland
Posted: 30th May 2007 15:14
I want to check if the objects position has reached a certain distance but it wont respond to this code that I use to test it:

if object position x(5)<=-5 then end

Don't look behind you.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 30th May 2007 15:37 Edited at: 30th May 2007 15:44
My first thought was that DB was introducing casting or rounding errors into the system because of the use of float variables when they should be integers and vice-versa - even though the variable concerned in your snippet was unrelated to the actual problem.

When you move an object you are supposed to use floats - not integers and like LBFN says, if you use Move, then you should only supply the amount to move from the current position - excluding the current position itself.

Quote: "I need the shoot# because without it the bullet will only move while you are holding spacekey."


Do you know what shoot# is? I don't think so - that's why I pointed you to that tutorial. If you'd read it, I'm sure you would be using shoot instead of shoot#.

You need to understand the difference between floats and integers because the errors you are getting are more than likely related to that subject. There's a very good chance that your problem will crop up elsewhere in your program - for the same reason.

TDK_Man

Conor B
19
Years of Service
User Offline
Joined: 10th May 2005
Location: Dublin, Ireland
Posted: 30th May 2007 15:55
Quote: "Do you know what shoot# is? I don't think so - that's why I pointed you to that tutorial. If you'd read it, I'm sure you would be using shoot instead of shoot#. "


TDK_Man: After I posted the first post I changed shoot# to shoot but it didnt make a diference, I know that the # is for real numbers and the shoot is for integers. Anyway I got the problem fixed now after changing the code to something similar to what LBFN posted, thanks everyone.

Don't look behind you.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 30th May 2007 16:23
Quote: "After I posted the first post I changed shoot# to shoot but it didnt make a diference"


Then why did you say in your second post:

Quote: "I need the shoot# because without it the bullet will only move while you are holding spacekey."



Quote: "I know that the # is for real numbers and the shoot is for integers."


That wasn't obvious from your posts. You'd be surprised how many people think that the # on the end of a variable makes it a numeric variable.

You have to appreciate that your questions will be answered on what you say - not what you mean...

But the main thing is that you've solved the problem now!

TDK_Man

Conor B
19
Years of Service
User Offline
Joined: 10th May 2005
Location: Dublin, Ireland
Posted: 30th May 2007 20:23
Ok, thanks TDK, by the way nice tutorials.

Don't look behind you.
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 31st May 2007 00:18
Quote: "That wasn't obvious from your posts. You'd be surprised how many people think that the # on the end of a variable makes it a numeric variable.
"

That is what the tutorial said

Ling creckt tsi nocreckto havela? NASA chetallnar mo lu'ul nasding!
Conor B
19
Years of Service
User Offline
Joined: 10th May 2005
Location: Dublin, Ireland
Posted: 31st May 2007 00:22
The tutorial doesn't say that the # makes the value of a number, It says that when using number variables you use the # for numbers with decimal places (real numbers).

Don't look behind you.

Login to post a reply

Server time is: 2024-11-25 18:04:48
Your offset time is: 2024-11-25 18:04:48