Array index out of bounds?
Blitz3D Forums/Blitz3D Programming/Array index out of bounds?
| ||
Can someone please tell me why array index is out of bounds, when it's clearly not? Here's the media & source files: http://www.mediafire.com/?btghxqav03ua2t6 I couldn't make a demo this time, because it's complaining about the array -.- Sorry Guys.... Thanks guys! :) |
| ||
Where are you getting the error? This actually works perfectly when I run it, debug mode or not. I had no trouble creating an exe and using all functions listed at the top of the screen. |
| ||
This line: Map(X,Y)=ReadInt(FI) in both loops |
| ||
Can you post instructions on replicating the error? (i.e. where exactly do we have to place objects, switch to G mode, load, save, whatever... in sequence?) |
| ||
Alright. Well. 1st thing I did was went into the level editor. (editor1.bb) I then drew a couple of test tiles in random places on the green background (or map), then saved the map by pressing F1. Then I closed the level editor. Opened it, pressed F2 to load the map, I THEN took lvl1.map that the level editor generated, and put it in the Game folder, and it worked fine in the LEVEL EDITOR. BUT in the GAME for some reason, I'm getting that stupid array index is out of bounds error, when it clearly is NOT >< Here's the level editor: http://www.mediafire.com/download.php?btghxqav03ua2t6 Let me know if you need more information! :) Thanks, Yasha :) Last edited 2012 |
| ||
Oh, whoops. I only thought to test the editor - didn't realise there was meant to be a game as well. The other three files are Hud.bb, scancodes.bb and testlevel.bb. Going out on a limb and assuming scancodes isn't the game, neither of the other two work due to a missing Include "Globals.bb". So you might want to update the download... |
| ||
O, ignore that... Here's the new files, 2 zip files contained in 1 master zip file. just extract the main zip file, then extract the other 2. I have included both the game AND the level editor in this update. with ONLY the files needed for them both to run. http://www.mediafire.com/?sgn80045htdl4aw Thanks, Yasha! :) |
| ||
Wtf? I reset IDEAL, and the stupid thing works o.O... That is SO weird... Anyways, now that it works, can u tell me why it's not drawing the tiles like it should? |
| ||
...well actually I can tell you what the error is in the version you just uploaded. Classic one: your Dim statement comes after your call to Load. So initially the array has no elements. Blitz is a bit weird this way in that globally declared names are visible throughout the program no matter where the declaration happens, but the initialisation (either sizing an array or putting things into a global) happens "in sequence" as you go down the main scope. As for the other bit... it draws what I quickly drew out in the editor (once the Dim statement is moved above the call to Load). What's going wrong there? Last edited 2012 |
| ||
Ok, I replaced the code for the Game. Here's the fix for Dim, but for some reason, I can't get it to draw the tiles in the right places: It's not drawing my tiles at ALL o.o Even though it reads the file Last edited 2012 |
| ||
Once again, this seems to work fine for me. Loads my smiley face map correctly. |
| ||
wtf?... o.o Why wont it load my Ztileset.bmp map? :/ |
| ||
Ok, it seems to work now.. I don't know WHAT it is with IDEAL. Now... One more question, then this is complete :) How can I make a map the same size as the map in the game? Is there a way I can make the level editor allow for scrolling with the arrow keys so that I can create a map the same size as the one in the game? :) |
| ||
All you have to do is have an offset for the current top left corner of the editor view. Draw the tiles "For x = xOffset to screenXsize + xOffset" and "For y = yOffset to screenYsize + yOffset" or something like that, and make sure that the maximum value for the offsets is "maxXsize - screenXsize" and the equivalent for Y. You might want to make your map sizes variable and load them from the saved map file, too; just make them the first two ints saved to the file, and read before the tile loading loop. |
| ||
How do I get the offset for the current top left corner of the editor? |
| ||
Here's what I have so far: |