Arrays, data and combining
Blitz3D Forums/Blitz3D Beginners Area/Arrays, data and combining
| ||
I'm trying to use a list to build a 3D level from tiles, and I'm having some problems. This is a stripped version of the code I'm using: ============================= For plop=1 To 7 Read levelData u.tile = New tile u\entity = CopyEntity(tile+levelData) Next Data 1,3,1,2,1,3,1 ============================= What I try to do is to read a number (which works), and combine that number with 'tile' so that it'll correspond with earlier defined globals 'tile1', 'tile2' and 'tile3'. This doesn't work. When I try it this way, I get MAV's and with other write-ups it even opens requesters to open other blitz files while compiling!! So my questions are: * How can I access a single variable by combining multiple pieces of it's name? * How can I navigate through data or arrays without having to define it's exact length? In Director Lingo you have lists (arrays), and you can see how long they are by requesting list.count, and you can add to them by add list,value. Is this possible in Blitz? |
| ||
Your CopyEntity command is tryinig to copy entities with handles that represent numeric values 1,3,1,2,1,3,1 you need to reference the tile numbers to the handles of their specific entities |
| ||
You can't reference a global "tile1" with tile+1. All this will give you is the value of "tile", added to 1. Instead of using tile1, tile2, etc, use an array: dim tile(3);this dimensions the array tile(1)=load_whatever tile(2)=ditto tile(3)=you_get_the_picture For plop=1 To 7 Read levelData u.tile = New tile u\entity = CopyEntity(tile(levelData)) Next Data 1,3,1,2,1,3,1 |
| ||
Anthony: yep, I got almost the same solution myself, although yours is a bit more efficient and I will implement that. Thanks! I know I wasn't doing the right thing, but in Director it's possible to refer to a variable by 'building' the variable name from seperate components (in this case it would work if I'd used u\entity = copyEntity(value("tile"&levelData)). I guess that's the curse of switching languages... I got a solution for my second question by the way: I just put a terminator 'magic number' at the end. So if the levelData = 0, it breaks the loop because it knows there won't be any other values coming. |