Sanctus's problem's topic
BlitzMax Forums/BlitzMax Beginners Area/Sanctus's problem's topic
| ||
Since I always have problems I decided not to fill the forum with stupid questions and insted to put my questions and problems here So here is the first one: Strict Global terrain_img:Timage Type Tmap Field xtiles:Int Field ytiles:Int Field map:Ttile[,] End Type Type Ttile Field x:Int Field y:Int Field img:Int ' just the frame for the terrain_img End Type Global map:Tmap = New Tmap map.xtiles = 128 map.ytiles = 128 map.map = New Ttile[map.xtiles , map.ytiles] Local i:Int Local t:Int For i = 1 To map.xtiles For i = 1 To map.ytiles map.map[i , t].img = 1 Next Next Atempt to acces field of null object... Can anyone help me and tell me how to avoid these things in the future? |
| ||
For i = 0 to map.xtiles-1 For t = 0 to map.ytiles map.map[i,t].img = 1 Next Next First failure 'i' in the second loop should be 't' ;) Second Failure: Arrays in Bmax are zero related, that means you create an array like this MAP:TTiles[256]. So the size of the array is 256, but not as in BB the index doesn't range from 1 to 256. instead it goes from 0 to 255. |
| ||
map.map = New Ttile[map.xtiles , map.ytiles]Only allocates the array, but not the type instances, you have to create those seperately, so your for..next loop could look like this: For i = 0 Until map.xtiles For i = 0 Until map.ytiles map.map[i , t] = New Ttile map.map[i , t].img = 1 Next NextAnd as mentioned above, the indices of an array go from 0 to size-1, you can use 'Until' instead of 'To' in a for..next loop to skip the last number. |
| ||
For i = 0 To map.xtiles-1 For t = 0 To map.ytiles-1 map.map[i, t] = New TTile Which I told you yestrday |
| ||
Strict Global terrain_img:Timage Type Tmap Field xtiles:Int Field ytiles:Int Field map:Ttile[,] End Type Type Ttile Field x:Int Field y:Int Field img:Int ' just the frame for the terrain_img End Type Global map:Tmap = New Tmap map.xtiles = 128 map.ytiles = 128 map.map = New Ttile[map.xtiles , map.ytiles] Local i:Int Local t:Int For i = 0 To map.xtiles-1 For t = 0 To map.ytiles-1 map.map[i, t] = New TTile map.map[i , t].img = 1 Next Next You need to initialise each item in the array as a TTile before accessing them. And arrays are zero based |
| ||
yeah thx but why don't they store some object???? I modified it like this For i = 1 To map.xtiles-1 For i = 1 To map.ytiles-1 map.map[i , t].img = 1 Next Next srry till i finished posting there where 4 more replys :D |
| ||
I found a article about exttreme programming and its way better that I was doing... The ideea of not making the program expadable saves me a lot of time and its easyer to fo like that... why define all the types from the beginning when I will use some only at the end... |
| ||
Added a few things and Im again in problemsStrict Graphics 800,600,1 Global terrain_img:Timage = LoadAnimImage("gfx\terrain.bmp",32,32,0,4) Type Tmap Field xtiles:Int Field ytiles:Int Field map:Ttile[,] End Type Type Ttile Field x:Int Field y:Int Field img:Int ' just the frame for the terrain_img Method drawself() DrawImage terrain_img , x * 32 , y * 32 , img End Method End Type Global map:Tmap = New Tmap map.xtiles = 16 map.ytiles = 16 map.map = New Ttile[map.xtiles , map.ytiles] Local i:Int Local t:Int For i = 1 Until map.xtiles For t = 1 Until map.ytiles map.map[i , t] = New Ttile map.map[i , t].x = i map.map[i , t].y = t map.map[i , t].img = 1 Next Next While Not KeyHit(key_escape) Local i:Int Local t:Int For i = 1 Until map.xtiles For t = 1 Until map.ytiles map.map[i , t].drawself() Next Next Cls Flip Wend the thing is that is doesn't draw anything... any ideeas of why that happens? |
| ||
pls help me.... I'm still in need of help |
| ||
hmmm... cls flip thats why there was a problem... I din't think it might make a diference if I change the order of those 2 |
| ||
http://www.blitzbasic.com/Community/posts.php?topic=62083 |
| ||
O'm not totaly beginner... Just that I din't changed the order of cls and flip(never) So by doing that I didn't think that was the problem(I didn''t even noticed) |
| ||
Before posting anymore bugs or problems, please start using SuperStrict. It will lead you halfway home. |
| ||
I didn't really get the oin in using superstrict instead of strict....but if you say so.... |
| ||
Superstrict fixes the compiler to work more like it should. I'm being a bit of an ass about that, but it's true on many levels. Superstrict will catch a lot of the ludicrous errors that Blitz lets you make by default. |
| ||
@Sanctus, skip the first chapter |
| ||
Heck no!!!!!! its 60 usd!!!!!!way to much for me(I'm 14) |
| ||
can bmax load gifs?(i never tryed and to ber shure that thats the problem in my code) |
| ||
found out that It can not... Question where is a tutorial with readdata(the maps from the source) In my ther pacman I used a lvl editor and now i wanth to load them from the .exe |
| ||
Sanctus, you're a brave lad, welcome to the world of Blitzmax documentation :- "ReadData : Read classic BASIC style data." Now, that should be enough according to BRL. Next question? |
| ||
Here's an example :-For i=1 To 5 RestoreData mydata 'reset the data pointer everly loop so we don't read past the end ReadData name$,age,skill Print "name="+name+" age="+age+" skill="+skill Next #mydata 'program label that can be used with the RestoreData command DefData "Simon",37,5000 There are 3 commands. RestoreData, ReadData and DefData. Defdata is used to actually define your data. Usually you mark the start of your data with a label - see the # symbol in the code above. This label is so you can tell BM where to begin reading the data from the next time you do a ReadData. (You can have as many chunks of data as you like, each with their own label, so you can for example have each of your game's level data with it's own label) ReadData is used to load that data into variables at run-time. Each time you read a peice of data, the current data pointer moves to the next peice and so on. RestoreData is used to tell BM where to begin reading the next item of data the next time ReadData is called. |
| ||
Sanctus, you're a brave lad, welcome to the world of Blitzmax documentation :- "ReadData : Read classic BASIC style data." Now, that should be enough according to BRL. Next question? I LOL'd. |
| ||
@Brendane thx man I think I'll get it working :D |
| ||
Sanctus, if you just want to know how to use those functions for the sake of learning, great. But if your aim is only to ensure that your exe contains the level data there is another way (presuming you already have the data files on disk). Use IncBin to import files into your final exe. These files can then be loaded without any modification just by using "incbin::" before the file you wish to load. Example :- IncBin "level1.dat" Global currentLevel:TLevel = LoadLevelData( "incbin::level1.dat" ) This can be much more flexible in the long run than using DefData for your level data. Why? Because you can create and modify your datafiles with a level editor - something you'll wish you could do if you end up needing to modify 1000 lines of DefData statements. Remember, you can IncBin any kind of file - images, sounds, whatever. When you need to load the file just put "incbin::" before it (so the load routine knows where it lives). Magic eh. |
| ||
nah it isn't that the reason but it takes a lot of time to make a lvl editor.... I will make it but later when the game will have some reasons to have playble lvls thx cuz u helped me a lot... i mangaged to make it read the walls from data(and miracously when I wrote it I din't got any bugs in my code...for the first time) |
| ||
Oh here is the code(tell me if you see something that is not right)SuperStrict Graphics 800,600,32 Global wall_img:Timage = LoadImage("gfx\wall.bmp") Global pac_img:Timage = LoadImage("gfx\pacman_stand.bmp") Global pac_left_img:Timage = LoadAnimImage("gfx\pacman_left.bmp" , 32 , 32 , 0 , 4) Global pac_right_img:Timage = LoadAnimImage("gfx\pacman_right.bmp" , 32 , 32 , 0 , 4) Global pac_up_img:Timage = LoadAnimImage("gfx\pacman_up.bmp" , 32 , 32 , 0 , 4) Global pac_down_img:Timage = LoadAnimImage("gfx\pacman_down.bmp" , 32 , 32 , 0 , 4) Type Tgame Field lives:Int Field points:Int Field lvl:Int Field map:Tmap = New Tmap Field player:Tpacman = New Tpacman Field wall_list:Tlist = New Tlist Method testload() RestoreData Map1_Wall ReadData map.xtiles , map.ytiles Local i:Int Local t:Int For i = 1 To map.xtiles For t = 1 To map.ytiles Local x:Int ReadData x If x = 1 Local wall:Twall = New Twall wall.x = (i - 1) * 32 wall.y = (t - 1) * 32 wall_list.addlast(wall) End If Next Next End Method Method drawall() Local wall:Twall For wall = EachIn wall_list wall.drawself() Next End Method End Type Type Tpacman Field x:Float Field y:Float Field dir:Int Field frame:Int Method drawself() Select dir Case 0 DrawImage pac_img , x , y Case 1 DrawImage pac_left_img , x , y , frame Case 2 DrawImage pac_up_img , x , y , frame Case 3 DrawImage pac_right_img , x , y , frame Case 4 DrawImage pac_down_img , x , y , frame End Select End Method Method updateself() '/////////THE FRAME CODE///////////// frame = frame + 1 If frame > 3 frame = 0 End If '/////////END FRAME CODE End Method End Type Type Tmap Field xtiles:Int Field ytiles:Int End Type Type Twall Field x:Int Field y:Int Field img:Timage Method drawself() DrawImage wall_img , x , y End Method End Type Global game:Tgame = New Tgame game.testload() While Not KeyHit(key_escape) game.drawall() Flip Cls Wend #Map1_Wall DefData 6 , 6 DefData 1 , 1 , 1 , 1 , 1 , 1 DefData 1 , 0 , 0 , 0 , 0 , 1 DefData 1 , 0 , 1 , 0 , 0 , 1 DefData 1 , 0 , 0 , 0 , 0 , 1 DefData 1 , 0 , 0 , 0 , 0 , 1 DefData 1 , 1 , 1 , 1 , 1 , 1 |
| ||
Looks good to me mate. One thing I would suggest before you go any further is to use a 2d array to store your map (as opposed to your tlist of walls. Why? Because at some point you're going to need to perform checks on collision/available routes. That will be much more efficient by looking up your player position in a map array and comparing the value (is it a wall, or a power up, or a dot?). You already have the 2d array in concept (look at your data). |
| ||
you meen to store my wall objects in a array? I can do that... |
| ||
Hmm.... this is not a problem but I posted some gfx of mine in tha gfx section pls go there and view it :D |