Dimension Problem
BlitzPlus Forums/BlitzPlus Programming/Dimension Problem
| ||
This is so easy and basic, yet it doesent work... I first made a game in BlitzBasic but now i wanna improve it in BlitzPlus. This has caused many different problem, my game just couldnt be runned by BlitzPlus. I am writing this thread cause i know no other way out. Here is the deal: I have a mapeditor that i have programmed myself and when it saves the map it lookes like this: Dim map(800,100,2) Function Saveing(ThisFile$) Local Number spara = WriteFile("..\..\data\"+ ThisFile$ + ".tlv") For x = 1 To 800 For y = 1 To 100 For z = 1 To 2 WriteInt(spara,map(x,y,z)) Next Next Next CloseFile(spara) End Function Now when its beeing loaded it looks like this: ladda = ReadFile(ChoosenFile$) For x = 1 To 800 For y = 1 To 100 For z = 1 To 2 map(x,y,z) = ReadInt(ladda) Next Next Next This is so easy! I know how to do this and it worked in BlitzBasic but now all i get is that "Array index out of bound" And this is just one of many problems i've had since i changed IDE Thanks |
| ||
Posted code looks OK. (BTW, try using the [code][/code[ codes when posting code) You didn't say WHEN you receive the error; during loading or saving or otherwise... Let us know that, and any other pertinent information. You may have to post more code as well. Arrays are Global by default, but make sure that (if your Dim statement is located inside of an include), that the include file is included in your code before the Saving/Loading functions. P.S. Saveing = Saving ChoosenFile = ChosenFile |
| ||
Looks ok to me too, there must be more to it! The tip is cool |
| ||
Allright. First of all excuse my bad english i'm from Sweden. All the globals and other variables are in the main program, underneath the variables i have my included files the "maploader()"-funktion is included. The "savemap()"-funktion is seperate with the mapeditor and works fine! The map is saved as it should and takes 625kb size. I belive it has something to do with the inclution of the code. Maybe i have to reset the map-variables in the included peace of code. I wouldn't have wasted youre time on such a simple thing if it wasent for the fact that this has worked before in BlitzBasic. Also maybe the OpenFile() is the wrong command, maybe it shoul be ReadFile() ?? I changed the load-funktion a little so that it looked like this: For x = 1 To 800 For y = 1 To 40;<<-- Alot less For z = To 2 map(x,y,z) = ReadInt(ladda) Next Next Next And the loading part worked only it looked wrong. I think BlitzPlus has other rules on how to use the "Dim"-command and that's what im trying to figure out. Also this is frustating cauze i ment to make the maps bigger in this sequal and change the hud, add a new bazooka, add a new enemy, add a highscore and finaly release it for free. Me and a friend made the first game as a schoolprojekt and got highest grade on it. Now i need a nicer one to show for the university that i plan to join after my service in the military. Anyway i havent finished my first point of the plan and time is running out. Are you guys proffesionals or do you just programme for fun on youre spare time? Just an inocent question... Thank you for youre help! |
| ||
AFAIK, the Dim command in B+ is identical to the one in B2D. You made it sound like you were concerned about the file size of your map. Most likely, the reason is because you are saving integers. Integers take up 4 bytes of data. If you don't require all 4 bytes (and I doubt that you do), you should look into writing/reading Shorts, or even Bytes (WriteShort, WriteByte). OpenFile and ReadFile act the same if you are only Reading. The only difference is that OpenFile also allows you to write as well. Perhaps try posting more of your code (the relevant parts) and maybe we can help more. (Don't forget to use the [codebox][/codebox[ commands.) |
| ||
Thank you! I'll look in to that right away... |
| ||
Well, it did decrease the filesize of my maps quite a bit but didn't solve the problem... I will soon add more code, maybe even the full sorce, hell i might give the whole mapeditor for anyone who would like it... I just need a server pretty bad =( Well you might wonder why i'm writing this at NewYears Eve, =) well, im writing this between the rounds of a dart game. (And i won the first one) Well Happy New yer to y'all and keep on the good work! |
| ||
You can download the OLD game at: <A href="http://www.lewser.se/berserker/downloads/tormenajtor.html">my site</A> There is a mapeditor included in the .zip-file but no sourcecode. The sourcecode can be added if requested for a short look. And plaesa go ahead and vote on my OLD game<a href="http://www.blitzbasic.com/gallery/view_pic.php?id=554&gallery=&page=6">here</A>. Basicly what the mapeditor does is saving variables in map(x,y,z). map(xposition,yposition,frame), and every value in the map is 20*20 in size. |
| ||
I don't see the point in looking at the OLD game. Show us the code to the new game so that we can find the problem. |
| ||
Allright! Here are the files: // www.lewser.se/berserker/downloads/MapEditor.bb www.lewser.se/berserker/downloads/Save_and_load.bb www.lewser.se/berserker/downloads/maploader.bb \\ But if you wanna se how the mapeditor works youll have to download the game. cuz i dont wanna put all the graphics out there on the net. Even if this is all very simple(maybe even bad) code i have put some hours on it. Downloading the game isn't that importent but i will soon add the new mapeditor on the server, maybe even tonight. |
| ||
ok go to my site http://www.lewser.se/berserker/ klick on "Downloads", then New Mapeditor. Read the readme first and download the castle2.tlv aswell. This is the new mapeditor incase you wanna see how it works. The sourcecode has already been given to you and can be found on the links in previous post. These are not acessable via the site. You'll still need to download the OLD game on the site, just replace the mapeditor with this new one. Sorry for doubleposting =( |
| ||
OK, first of all, I thought that in your initial post, the problem you were having was in the loading function of your GAME. It now appears that all this time you were talking about the problem being in the loading function of the new MAPEDITOR you are writing? I'm a bit confused. The reason I ask, is because I am trying to understand HOW the source files you posted above fit into this problem. The first one is MapEditor.bb. That is self-explanatory, the source code for the map editor. I see that in MapEditor.bb you include the Save_and_load.bb file, so I know that MapEditor.bh and Save_and_load.bb are both for the map editor. I don't know how the third file (maploader.bb) is used though. Is that file used by the map editor? (because if it is, I don't see an Include command in MapEditor.bb) or is it used by your game? Please explain the above. ----------------------------------------------------------- Looking at the code in maploader.bb... Are the following variables global variables in the file that includes this maploader.bb file? ChoosenFile$ Map_X_Max Map_Y_Max Because if they aren't, they would probably cause your 'Array index out of bounds' error. I don't know what this code is for If (x < Map_X_Max) And (y < Map_Y_Max) Then For xm = 1 To 20 For ym = 1 To 20 mapcheck(((20*x)+xm),((20*y)+ym))=Value;Här är något lurt! Next Next EndIfbut it appears that you could have an 'array index out of bounds' error if 'mapcheck()' hasn't been DIMmed. Also, 20*x will be a LARGE number. Make sure that that code is written correctly and make sure that mapcheck() is DIMmed large enough. |
| ||
Are you sure of WHERE the error is being caused? Maybe it's not really part of your map loading routine. Add some DebugLog commands to your code to find out where the error is generated. If you know where it's generated, then tell me which line number and which file it happens on. |
| ||
First of all i must say thank you very much! I love youre entusiasm! The maploader.bb is included in the game and is used to read the short-values in the .tlv-files (wich are maps). It reads the values and stores them in "map(x,y,z)" the mapcheck(x,y) is the array where the fysik part of the map is stored... Im gonna try to explain better. When the map is drawn on the screen the program need to know what part of the map that needs to be displayed, eg. if the player is at the end of the map then the game doesent need to write the start of the map. The map(x,y,z) is used to know what to write and every object is 20*20 pixels in size, therefor the real map (the fysikal map where the player walks and so on) so there needs to be another dim to cover that mapcheck(x*20,y*20). mapcheck(x*20,y*20) will always be =1 if theres anything at all in the map(x,y,z), otherwise mapcheck(x*20,y*20)=0. But rightnow its the maploader.bb that seems to be strange. Row:15 Col:8 in maploader.bb says "Array Index Out Of Bounds" Const Map_X_Max = 800 Const Map_Y_Max = 100 ^^ this is the size of the map wich it is saved in the mapeditor. This means that: Dim mapcheck(Map_X_Max*20,Map_Y_Max*20) the z-value in map(x,y,z) only holds the frame of the animated images so it's not needed in mapcheck(x,y) The code that you didnt understand is for filling out mapcheck(x,y) form one point to 20pixels further. Right now the problem is in reading from the file *.tlv and store into map(x,y,z)... It does work if i shorten the y-value down to 40 though For x = 1 To 800 For y = 1 To 40 For z = 1 To 2 map(x,y,z) = ReadShort(file) Next Next Next But in the mapeditor the map is saved as 800*100*2 Hope i have cleared somthing up. Anyway what do you think of the mapeditor? Would it be good enough after i fixed it to add it here (for free ofcourse) if i add some more textures and maybe more enemies? |
| ||
OK, Row 15 is this line:map(x,y,z) = ReadShort(ladda)of this code For x = 0 To Map_X_Max For y = 0 To Map_Y_Max-60 For z = 1 To 2 map(x,y,z) = ReadShort(ladda) Next Next Nextin maploader.bb What that means then is that map(x,y,z) is not DIMmed large enough for either x, y, or z. 2 reasons: 1. Not DIMmed at all 2. Not DIMmed correctly Looking at 1. Not DIMmed at all The DIM statement for map() may be missing entirely or it may be located on a line AFTER the Include "maploader.bb"line. Double check those two things. Looking at 2. Not DIMmed correctly At the beginning of this thread, you stated that map() is DIMmed like so: Dim map(800,100,2)BUT that that statement is part of your mapeditor. In your last post you stated this: The maploader.bb is included in the game So, I haven't actually seen a statement yet that shows how you DIM map() for maploader.bb.Make sure that map is DIMmed correctly in file that Includes maploader.bb. If it is DIMmed with Global or Const Variables, make sure that they exist and that they are decared before the Include "maploader.bb"line. |
| ||
Its one of the first things in the code actually, i prefer to have constants in the start of the code and globals after... Anyway this is how the code looks in the game-file called MainCore.bb:AppTitle "TÖRMINÄjTÖR 2 : A Second Arrival" Const ScreenWidth = 1280 Const ScreenHeight = 1024 Const ScreenDepth = 32 Graphics ScreenWidth,ScreenHeight,ScreenDepth,2 SetBuffer BackBuffer() Const Map_X_Max = 800 Const Map_Y_Max = 100 Dim map(Map_X_Max,Map_Y_Max,2) Dim mapcheck((Map_X_Max*20),(Map_Y_Max*20)) Then alot of Globals for different uses... Then after the globals: Include "..\..\data\maploader.bb" Include "..\..\data\walk.bb" Include "..\..\data\maprender.bb" Include "..\..\data\Info.bb" Include "..\..\data\Weaponcontrole.bb" Include "..\..\data\Check.bb" Include "..\..\data\fiende.bb" Then the functions of the game. Conclution: The map() is Dimed correctly but maybe it's read wrong? Is there some kind of unwriten law about starting from zero? ;Like this For x = 0 To Something For y = 0 To Something For z = 0 To Something ;And so on Next Next Next I know that the error occurs there on row 15, but im not sure if the error is in the saving process or the loading, i mean that maybe the map doesent contain 100y? The error does occur in the loading process and the mapeditor works fine (test it for futher understanding), but i dont know... As i said before this has worked in BlitzBasic i have only changed a few things such as taken away all code containgn the command "Locate" and increased the mapsize to 800*100 it was 100*40 before. |
| ||
I tested this code Const Map_X_Max = 800 Const Map_Y_Max = 100 Dim map(Map_X_Max,Map_Y_Max,2) Dim mapcheck((Map_X_Max*20),(Map_Y_Max*20)) ;write spara = WriteFile("c:\test.txt") For x = 0 To Map_X_Max For y = 0 To Map_Y_Max For z = 1 To 2 map(x,y,z) = $ABCDEF12 WriteInt(spara,map(x,y,z)) Next Next Next CloseFile(spara) ;read ladda = ReadFile("c:\test.txt") For x = 0 To Map_X_Max For y = 0 To Map_Y_Max For z = 1 To 2 map(x,y,z) = ReadInt(ladda) Next Next Next and it works fine with debug on. All arrays are automatically made from 0 to the size you specify so you actually get and extra "slot". Note that I ran x and y from 0 so actually processed 801 columns and 101 row but ran z from 1 to 2 (only 2 x 3rd dimensions). I used a hex viewer to view the data.txt file and each integer (4 bytes) is written as $12EFCDAB which is worth knowing. You could use a hex viewer to check that your map files contain the correct/expected integers at the correct positions. From the example code at the top of this thread to the real code lower down you have changed things like the For loops from "1 to whatever", to "0 to whatever". Is this intentional? Also you have used ReadInt and later ReadShort, is this intentional? Good Luck |
| ||
I could wreally use a Hex Viewer where can i find one? The For x = 0 To Anythong was just a question, wich you've answered. Its not part of the code dissregard it. As for the ReadInt, nevermind even though it makes no differense it's supposed to be ReadShort. Maybe a Hex Viever can help me solve this whole dilemma? -------------------- Anyway, say this whole problem would be solved, am i doing it right with the mapcheck(x,y) filling? I mean: ;Allright this basicly means that ;mapvalues below 12 is "walkable" (dirt,sand,stone) ;mapvalue 0 is nothing (this is were the player falls down) ;mapvalue > 12 is things like mines, enemies and misc ;so while the map is loading we need to fill the ;mapcheck(x,y) with the value 1 = ;(the player will bump in to theese things) ;\\\\\ If (map(x,y,1) <> 0) And (map(x,y,1) < 12) Then Value = 1 Else Value = 0 EndIf If (x < Map_X_Max) And (y < Map_Y_Max) Then For xm = 1 To 20 For ym = 1 To 20 mapcheck(((20*x)+xm),((20*y)+ym))=Value Next Next EndIf ;///// i'm wondering this since it seems to be aproblem aswell. But previously posted problem is of most importense. Thank you for your'e cooperation. |
| ||
I know that the error occurs there on row 15, but im not sure if the error is in the saving process or the loading, i mean that maybe the map doesent contain 100y? The problem is in the loading. Heres why: ReadShort (filehandle/stream) Parameters filehandle/stream = a valid variable set with the OpenFile, ReadFile command, or OpenTCPStream (v1.52+) The value returned is an integer in the range 0-65535. Description Once you've opened a disk file (or stream) for reading, use this command to read a single short integer (16bit) value from the file. Note, each value written uses 2 bytes of disk space and is written least significant byte first. Reading beyond the end of file does not result in an error, but each value read will be zero. Note again the last sentence. ReadShort() WILL NOT FAIL even if your saving code is incorrect, so that is not the problem. The problem is how the map() array is defined. There must be something you are not showing us. Or something... |
| ||
I have a hex viewer that I made, it's not great but I can email it to you for free if you trust me with your email address. There's probably loads of better ones on the web, try a Google search. Wolron? Is your tag line supposed to say hoes or holes. Sounds pretty rude either way. Am I being dumb? regards |
| ||
Interesting... The map was saved (and read) with Integer at first, but i got tipped to margain the filesize by changing to Short. I think i have solved it pretty much now, as my tag "Det är inte fel det stämmer bara inte" meaning "It's not wrong it just doesen't make sense" (a qoute from a classmate, haha smart), it doesent give me an error anymore but it doesent work fully as i wish. I've been working on it almost half the day now. Sure i'd be happy to give you my email no problem! Go ahead and add me to ICQ while youre on it! But all you gotta do is clik on my nickname and you'll be sent to my profile page. The email is there... Anyway my email is: berserker@... I can't thank you enough for all your kind help, if it means anything i'll add you all to my credits as "Special Thanks". I'll keep you updated since theres still some errors to fix and it will never be quite good enough right? I've been shifting between project too long now, i need to settle down and finish something before i can move on. |
| ||
I'll email you the Hex Viewer later when I'm at home. How did you solve it? Was it just down to the Integer/ShortInt map file problem? Thanks for the tip about the profile page! |
| ||
Well im ebarrased to tell... Since the program failed at my first go when i changed IDE i "commented" som functions so that they wouldnt run. Some shit-functions like updating weapon info and such, as i gradually let them be in the game one of them had a redefinition of Dim map(100,40,2). Well it didn't have to be that but part of it. Anyway it's still loads of problems since i increased the resolution. I'll be right back with new problems for you to solve hehe =) |