Storing Decimals in an Array
Hi,
I'm making a tile based level editor for a game, and am storing the tile number, followed by its direction in a single array, where the X and Y indexes are the grid co-ordinates of the level.
I wanted to store the number as:
TileNo.Direction
Using the calculation:
TileNo + (Dir("Tile")/80)
So:
Tile1, Direction 0 = 1.0
Tile1, Direction 8 = 1.1
Tile1, Direction 16 = 1.2
Tile3, Direction 24 = 1.3
However when it is stored, it is automatically stored as an Integer. (The Array is set as a 'Number Array')
Is there any way to change this, or maybe an easier way to store TileNo and Direction without using 2 different Arrays?
Thanks in advance.
Re: Storing Decimals in an Array
It's a clever idea, but I'm not sure that you'll get it working like that (I'm still uncertain about how MMF decides whether things are integers or floats, to be honest). Could you rework it so that the direction and tile number are combined into an integer?
TileNo*4 + Dir("Tile")/8
You'd have to set up your array to divide the tile number out again, though.
Of course, you could always shove some *1.0s into it and see what happens. I think the most likely thing to work is using /80.0 instead of /80.
Re: Storing Decimals in an Array
As far as I'm aware, the array is for integers only. Regardless, I would avoid decimals if possible, as they do not have perfect precision due to computer limitations - regard them ONLY as an approximation to a value rather than a perfect representation.
Re: Storing Decimals in an Array
Thanks for your replies!
OT, DavidN: Good to see Crystal Towers 2 on its way! I remember reading an article on Teletext in the UK about Clickteam's products, and Crystal Towers was one of the games mentioned, which persuaded me to try out TGF :cool:
Re: Storing Decimals in an Array
To store a float as an integer, it's pretty easy, just multiply the float by 100, store it, and then divide it by 100 when loading... :)