forums

TNT Basic Forums > Programming Q&A
Only 256 numbered tiles! Is it true?
< Last Thread     Next Thread >
Author
Thread        Post A Reply

12-05-2003 12:12

Posted by:
Martin

Click Here to Email Martin   Find more posts by Martin


I need some help on this one.

I have a map, a simple grid, 25 tiles wide and l8 high, for a total of 450 tiles, 32 pixels square. However, I am able to "set" an id for only 256 tiles with code that generates 450 numbers. Why? Here's the code:

int gTileID[450]
int x,y,z.id,tn,number

for y=0 to 17
for x=0 to 24
Set Map Tile x,y,z,id
gTileID[tn]=id
print gTileID[tn]
'prints numbers "0" to "449".

number = Map Tile (x,y,z)
print "Tile " ; number
'prints numbers "0" to "255" followed
'by numbers "0" to "193" for a total of 450

tn=tn+1
id=id+1
next
next

After quite a few hours fooling around with a dozen different ideas, it dawned on me that the number 256 has a special significance: it's a byte - representing 256 pieces of information. It seems logical to assume that that fact is related to what the code produces but that still doesn't solve my problem. Using "Map Tile (x,y,z)" I'd like to be able to access 450 tiles.

How can I do that?

Thank you.

Martin


12-05-2003 23:59

Posted by:
-wyvern

Location:
Bedroom

Find more posts by -wyvern

Limitations, limitations...

You can do nothing apart from reduce the size of the array... This makes large games very difficult, especially RPGs with clouds of varables - sigh... Oh well, enough complaining about the glorious thing that is (sometimes) TNT. You'll find a way round it, even if you have to do some ugly coding (Wierd - every time I move into a bigger and better language I rapidly run into it's upper limits... curse my insatiable appetite for complexity...)

12-06-2003 04:02

Posted by:
Miles

Location:
Australia

Click Here to Email Miles   Find more posts by Miles

So you're saying that you can't use an array with more than 256 items?

I'm sure I've used arrays far bigger than that (Sometimes up to several thousand) without problems.

12-06-2003 09:04

Posted by:
Miles

Location:
Australia

Click Here to Email Miles   Find more posts by Miles

Meh, regardless, sometimes just rearranging/simplifying code with weird little errors like this can fix it. Perhaps try this instead:

int gTileID[Map Height*Map Width]
int x,y,z,id

for y=0 to Map Height-1
for x=0 to Map Width-1
Set Map Tile x,y,z,id
gTileID[y,x]=id
id=id+1
next
next

12-06-2003 11:51

Posted by:
Martin

Click Here to Email Martin   Find more posts by Martin

Well, I've been at work.

Miles, first I ran your code as follows:

int gTileID[Map Height*Map Width]
for y = 0 to Map Height - 1
for x = 0 to Map Width-1
Set Map Tile x,y,z,id
number = Map Tile (x,y,z)
print "Tile " ; number
id=id+1
next
next

Same result: runs to 255 and starts again.

Tile 254
Tile 255
Tile 0
Tile 1
Tile 2

Next, -wyvern, I did what I thought was clever rather than ugly: I ran two separate series of loops. The first was the same as I had before except that I ran for half the map...the upper half with an id from 0 to 224.

Then, with the id = 225, I ran the second half - figuring that the left hand wouldn't catch on to what the right hand was doing. The result was the same as before...resulting in a run from 225 to 255 when it started again with zero.

The problem, I believe is not the size of my array but the size of the map. I'm afraid you can't fool the Set Map Tile command, particularly its "id". I don't think y an id can be greater that 255 (256 elements). I guess this means that if you want a map on which you can number each tile, the number of tiles cannot exceed 256.

Is this true?

I'm going to spend the day looking for a downright ugly - nay ungainly - method of having each of 4800 tiles provide information to whatever sits on it. Perhaps I can put an informer on each tile and have it provide the information. Can two sprites occupy a tile at the same time? I've never thought about it. Any ideas?

Hopefuly,
Martin

12-07-2003 00:26

Posted by:
Miles

Location:
Australia

Click Here to Email Miles   Find more posts by Miles

I'm afraid I don't really understand what you're trying to achieve.

Sorry if you already know this, but you realise that "Set Map Tile" sets the image of that tile from the tile bank.

Why you'd want to have each individual tile a different image confuses me. The idea of a map is that you re-use basic tiling images to save time and memory.

I've never tried to have more than 256 different tile images, I wouldn't be surpised if you couldn't. There is normally no need.

12-07-2003 10:07

Posted by:
Martin

Click Here to Email Martin   Find more posts by Martin

As a someone new to maps and their creation but not unfamiliar with programming - although new to TNT - I'm not surprised that I completely forgot both the purpose of the "Set Map Tile" command, and more importantly the "id". Miles, I very appreciate your reminding me. Now I can understand the 256 limit.

I am trying to provide information to each of the 450 tiles, store each piece of data in an array, and then have it accessed during the operation of the program. The information varies with the tile.

Now I'm working on creating an array consisting of artificial tile numbers, map coordinates, and the information. This should work.

12-07-2003 11:01

Posted by:
Miles

Location:
Australia

Click Here to Email Miles   Find more posts by Miles

Ah. Good luck. :)

12-07-2003 11:22

Posted by:
Martin

Click Here to Email Martin   Find more posts by Martin

I finally worked out a way-around which doesn't depend on commands. Below is the code for loading three of the four "rows" of data. The last one. " gTileData [ 3, c ] ", will be loaded separately.


dim gTileData [ 4, 450]

for r = 0 to 17
for c = 0 to 24

gTileData [ 0, c ] = tID 'tile id
gTileData [ 1, c ] = tx 'its x coordinate
gTileData [ 2, c ] = ty 'its y coordinate

tID = tID + 1
tx = tx + 32
next

tx = 0
ty = ty + 32

next


Here's the printout for the first tile of the last row.

400
0
512

Here's the printout for the last tile of the last row.

449
768
544

Thank you, Miles, once again, for pointing out the obvious.

12-07-2003 12:33

Posted by:
Miles

Location:
Australia

Click Here to Email Miles   Find more posts by Miles

Okie dokies, well, it would help to know what type of game you're creating, but if it's the usual type where you want to test collisions with certain types of tiles (like wall tiles), then I'm afraid that code would not be very useful. Mainly because it's very awkward to reference tile infomation based on an arbitrary value. It would be much more useful to be able to reference tiles based on their position on screen.

Please explain to me what type of game you are making and what you are trying to do. Because if you're just trying to detect collisions with certain types of tiles, there are much easier ways to do that.

If you do decide you use the code you have, however, you should note that it sets information for "gTileData [ 0 , c ] " Now c is the counter for the if ( 0 to 24). Therefore it would just set the same variable 18 times over. I don't think that's what you're trying to do.

Miles

12-09-2003 00:42

Posted by:
Martin

Click Here to Email Martin   Find more posts by Martin

Miles, your write," it would help to know what type of game you're creating" and " ... it's very awkward to reference tile information based on an arbitrary value. It would be much more useful to be able to reference tiles based on their position on screen"

Fiirst of all, I'm sorry I didn't make myself clear or really describe what I am doing. My goal is to create a version of Sugarscape where the tiles are flat and there are no walls. Initially sprites move across this field looking for sugar...and so the need to read a tile's sugar content. Later, the action in the field will be limited by own imagination first and a player's later on.

Right now I'm working on a test version, just 450 32 pix. square tiles on a map of 25 tiles across and 18 down. (The final version, using 16 pix. square tiles, 80 x 60, will have 4800 tiles on a 1280 x 960 map.).

The tile numbers I assigned are arbitrary, Miles. The coordinates are not; they are the actual coordinates of the tiles in pixels. Later, information on the tile will be coded - say 1 to 5. Indeed, I may work out a method of storing an array on a tile.

You wrote that "If you do decide to use the code you have, however, you should note that it sets information for 'gTileData [ 0 , c ] ' Now c is the counter for the if ( 0 to 24). Therefore it would just set the same variable 18 times over. I don't think that's what you're trying to do."

I am, though. I'll explain

The code above fills an array of four rows 450 boxes long, as it were. Top row holds the id of a tile - numbers from 0 to 449, the second - its x coordinates, the third - its y coordinates. The bottom row - also 450 boxes long - will hold other information.

Yes, I know the variable is often set 18 times. Here's a section of the output I clipped out with y= 512.

417/544/512 | 418/576/512 | 419/608/512 |420/640/512 |421/672/512/

The first number in each series is the id, the second, its x coordinate (which increases by 32 with each loop) and then its y coordinate (512) which is repeated 18 times to access all the x coordinates on that row and then it, the y coordinate is augmented.

Thanks for your interest.

Martin

12-10-2003 03:39

Posted by:
Miles

Location:
Australia

Click Here to Email Miles   Find more posts by Miles

Ah. That makes sense. Sorry I didn't understand, I'm only trying to help.

What I mean with the array indexes is that you've indexed the gTileData array to 4, 450, which, I do realise you indend to fill with 4 pieces of information about each of the 450 tiles. Basically from what I gathered you indend from that code to get information about all 450 tiles. But when you set gTileData [ 0 , c ], c only ever goes between 0 and 24! So you'll get information about the first 25 tiles only (18 times over)!

Second of all, storing the "id" of something in an array in the first place doesn't really make sense, because the "id" should be the index itself.

For example, the tile information stored in gTileData [ n , 4 ] should refer to tile number "4". Therefore putting the number "4" in the array so that you can access the number "4" by saying gTileData [ 0 , 4 ] seems strange.

12-10-2003 14:06

Posted by:
Martin

Click Here to Email Martin   Find more posts by Martin


I know you want to help, Miles, and you've helped considerably. I appreciate it.

You write: "But when you set gTileData [ 0, c ], c only ever goes between 0 and 24! So you'll get information about the first 25 tiles only (18 times over)!"

I don't because after the first loop the code changes the values of the variable ty as well as returning tx to zero. See below for the commented line.

dim gTileData [ 4, 450]
for r = 0 to 17
for c = 0 to 24
gTileData [ 0, c ] = tID 'tile id
gTileData [ 1, c ] = tx 'its x coordinate
gTileData [ 2, c ] = ty 'its y coordinate
tID = tID + 1
tx = tx + 32
next
tx = 0
ty = ty + 32 ' Here's the key line of code.
next

If you still are in doubt, run the code. It will produce the number of each tile, its x coordinate and its y coordinate without duplicates.

You write: "Second of all, storing the "id" of something in an array in the first place doesn't really make sense, because the "id" should be the index itself."

I understand that now - thanks to you - but I'm not using the "id" as it exists in the command Set Map Tile x,y,z,id. I'm using it as one of own variables. I could have used "tileName" instead.

Martin

12-10-2003 21:17

Posted by:
Miles

Location:
Australia

Click Here to Email Miles   Find more posts by Miles

Ok, In order for you to understand what I mean, I want you to add the following to the bottom of your code:

Print gTileData[0,30]
Print gTileData[1,30]
Print gTileData[2,30]

Print the data for the 30th tile. That data should exist, shouldn't it?

But it doesn't.

It would exist, however, if you change this piece of code:

gTileData [ 0, c ] = tID 'tile id
gTileData [ 1, c ] = tx 'its x coordinate
gTileData [ 2, c ] = ty 'its y coordinate

To this:

gTileData [ 0, (r*25)+c ] = tID 'tile id
gTileData [ 1, (r*25)+c ] = tx 'its x coordinate
gTileData [ 2, (r*25)+c ] = ty 'its y coordinate

Sorry if I haven't made myself clear, that's what I meant.

12-11-2003 16:54

Posted by:
Martin

Click Here to Email Martin   Find more posts by Martin

I would never in million years have figured out the code that you suggested. Fantastic. Mine did not work as you knew and I didn't. I confess I was confused between the array and the map. In order to make sure what I was doing was right, I had used these pringt commands IN the loop:

Print gTileData [ 0, c ]
Print gTileData [ 1, c ]
Print gTileData [ 2, c ]

The output seemed correct. I didn't do what you suggested which is a sure test, i.e.

Print gTileData[0,30]
Print gTileData[1,30]
Print gTileData[2,30]

after the loop.

Even if I had and discovered it was wrong, I would have come up with some awkward combination of loops, not the beautifully simple yet very complex code that you did. I thank you very much.

Martin


12-12-2003 08:57

Posted by:
Miles

Location:
Australia

Click Here to Email Miles   Find more posts by Miles

You're welcome. ^_^

Good luck with the rest of the game.

01-15-2004 20:59

Posted by:
MapMaker

Location:
Edmonton, Alberta (Canada)

Click Here to Email MapMaker   Find more posts by MapMaker

Hmm..

Ive been reading through this to figure out how to use the set map tile function, but I can't quite seems to get it.

What is the 'z' value? (set map tile x,y,z,id)

And also, is the ID the number of the tile in the 'tile' window in the genesis section?

Thanks in advance,
MapMaker

01-16-2004 02:51

Posted by:
Miles

Location:
Australia

Click Here to Email Miles   Find more posts by Miles

Martin's code is not exactly very standard... I wouldn't follow it if you want to learn how to do the Set Map Tile command (it doesn't even use it anymore)

The 'z' value is the 'map layer' from which to get the tile. If you're just working with a single-layer map, then it would be 0.

Yeah, the ID of a tile is indeed the index of it's tile.

Something to note about Set Map Tile: The changes aren't permanent, they only stay so long as the Map remains in memory.

01-16-2004 18:56

Posted by:
MapMaker

Location:
Edmonton, Alberta (Canada)

Click Here to Email MapMaker   Find more posts by MapMaker

Hmm

Ok

Thanks,
MapMaker

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.