forums

TNT Basic Forums > Programming Q&A
variable questions
< Last Thread     Next Thread >
Author
Thread        Post A Reply

01-13-2007 03:26

Posted by:
chatsc

Click Here to Email chatsc   Find more posts by chatsc

1) what's the purpose in declaring the variable type (int, float, string)

2) why make distinction between int and float. If float accepts decimals, then wouldn't it suffice by itself without the need for int?

01-13-2007 03:52

Posted by:
JHVipond

Location:
South Dakota

Find more posts by JHVipond

The "Variables" section of the TNT Basic user guide should answer your questions. If you still don't understand, ask Mark or Danny.

01-13-2007 10:54

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

Float stores "1" like this: 1.0000000
int stores "1" like this: 1

So... Float takes more memory... But if you need the precision then by all means use it. Also, in "For... Next: structures, the "For x=0 to SomeNumber", x has to be an integer.

01-13-2007 12:29

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Good Questions...

So, some answers:

1: Variables are held differently by TNT, and handled differently according to type. Floats and Ints store numbers in different ways, and a String is just an address into memory (held in an int). TNT needs to know what you want to store so that it can allocate the correct type of variable, and so that it knows how to deal with it later. TNT uses 'Single precision' float values, so they take the same amount of space as an Int (32 bit, or four bytes), they do not use more memory.

2: Floats and Ints are related, but as I said above, they hold numbers in different ways. It takes longer to deal with a Float than it does to deal with an Int, so Ints are quicker but hold less precise values. Generally speaking you should use integer maths for things such as screen coordinates, lives, scores and other basic values, float point should be used for angles, 3D coordinates or physical values such as inertia, mass or momentum etc. Use float only if needed as they are slower...

Hope this helps.

Danny (nods)

01-13-2007 12:56

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Really Nerdy Bit...

Just as a quick note, if you want to know why Float point is slower than Integer you might like to take a look at this:

IEEE Standard for Binary Floating-Point Arithmetic (IEEE 754)

You'll never use Floats again... It's scary man!

Danny (nods)

01-13-2007 21:33

Posted by:
chatsc

Click Here to Email chatsc   Find more posts by chatsc

helpful

Yes, you've helped! Precisely what I wanted to know.
Thanks.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.