Xlithan Posted February 15, 2016 Author Share Posted February 15, 2016 Hi guys, I'm trying to create a map converter but it doesn't seem to be working properly. Below is some code from the main module which converts the maps, but I seem to be getting a Subscript Out of Range error on the following line:**NewMap.Tile(x, y).Layer(1).x = OldMap.Tile(x, y).Ground**```Option ExplicitSub ConvertOldMapsToNew()Dim FileName As StringDim FileName2 As StringDim m As LongDim i As LongDim F As LongDim x As Long, y As LongDim OldMap As OldMapRecDim NewMap As NewMapRec For i = 1 To MAX_MAPS FileName = App.Path & "\maps\map" & i & ".dat" FileName2 = App.Path & "\new maps\map" & i & ".dat" ' Get the old file F = FreeFile Open FileName For Binary As #F Get #F, , OldMap Close #F ' Delete the old file 'Call Kill(FileName) ' Convert NewMap.Name = OldMap.Name NewMap.Up = OldMap.Up NewMap.Down = OldMap.Down NewMap.Left = OldMap.Left NewMap.Right = OldMap.Right NewMap.BootMap = OldMap.BootMap NewMap.BootX = OldMap.BootX NewMap.BootY = OldMap.BootY For y = 0 To MAX_MAPY For x = 0 To MAX_MAPX NewMap.Tile(x, y).Layer(1).x = OldMap.Tile(x, y).Ground NewMap.Tile(x, y).Layer(1).y = OldMap.Tile(x, y).Ground NewMap.Tile(x, y).Layer(3).x = OldMap.Tile(x, y).Mask NewMap.Tile(x, y).Layer(3).y = OldMap.Tile(x, y).Mask NewMap.Tile(x, y).Layer(7).x = OldMap.Tile(x, y).Fringe NewMap.Tile(x, y).Layer(7).y = OldMap.Tile(x, y).Fringe NewMap.Tile(x, y).Layer(1).Tileset = 1 NewMap.Tile(x, y).Layer(3).Tileset = 1 NewMap.Tile(x, y).Layer(7).Tileset = 1 NewMap.Tile(x, y).Type = OldMap.Tile(x, y).Type NewMap.Tile(x, y).Data1 = OldMap.Tile(x, y).Data1 NewMap.Tile(x, y).Data2 = OldMap.Tile(x, y).Data2 NewMap.Tile(x, y).Data3 = OldMap.Tile(x, y).Data3 Next x Next y ' Save the new map F = FreeFile Open FileName2 For Binary As #F Put #F, , NewMap Close #F Next iEnd Sub``` Link to comment Share on other sites More sharing options...
Growlith1223 Posted February 15, 2016 Share Posted February 15, 2016 one of your maps are smaller than the other most likely, only thing i can think of else would be the .Layer() constructor isn't initialized? Link to comment Share on other sites More sharing options...
Genusis Posted February 15, 2016 Share Posted February 15, 2016 you will need to do something likeif x < old_maxx and y < old_mapy then NewMap.Tile(x, y).Layer(1).x = OldMap.Tile(x, y).Ground NewMap.Tile(x, y).Layer(1).y = OldMap.Tile(x, y).Ground NewMap.Tile(x, y).Layer(3).x = OldMap.Tile(x, y).Mask NewMap.Tile(x, y).Layer(3).y = OldMap.Tile(x, y).Mask NewMap.Tile(x, y).Layer(7).x = OldMap.Tile(x, y).Fringe NewMap.Tile(x, y).Layer(7).y = OldMap.Tile(x, y).Fringe NewMap.Tile(x, y).Layer(1).Tileset = 1 NewMap.Tile(x, y).Layer(3).Tileset = 1 NewMap.Tile(x, y).Layer(7).Tileset = 1 NewMap.Tile(x, y).Type = OldMap.Tile(x, y).Type NewMap.Tile(x, y).Data1 = OldMap.Tile(x, y).Data1 NewMap.Tile(x, y).Data2 = OldMap.Tile(x, y).Data2 NewMap.Tile(x, y).Data3 = OldMap.Tile(x, y).Data3else NewMap.Tile(x, y).Layer(1).x = OldMap.Tile(x, y).Ground NewMap.Tile(x, y).Layer(1).y = 0 NewMap.Tile(x, y).Layer(3).x = 0 NewMap.Tile(x, y).Layer(3).y = 0 NewMap.Tile(x, y).Layer(7).x = 0 NewMap.Tile(x, y).Layer(7).y = 0 NewMap.Tile(x, y).Layer(1).Tileset = 1 NewMap.Tile(x, y).Layer(3).Tileset = 1 NewMap.Tile(x, y).Layer(7).Tileset = 1 NewMap.Tile(x, y).Type = 0 NewMap.Tile(x, y).Data1 = 0 NewMap.Tile(x, y).Data2 = 0 NewMap.Tile(x, y).Data3 = 0end if Link to comment Share on other sites More sharing options...
Xlithan Posted February 15, 2016 Author Share Posted February 15, 2016 Layer constructor? It should be a very simple program, all you're doing is loading values into one variable, and saving them in another lol.The major difference, and the only one I can see from the 2 systems, is the Layer() stuff. Most older source codes just use .Ground, .Mask, .Fringe etc. From what I can gather, the Layers are exactly the same thing, but they're set as arrays instead of singular.With that, Layer(1) is the ground layer, Layer(3) is the mask layer, and Layer(7) is the fringe layer.What exactly is the difference between the Layer().x and Layer().y? Since older systems just use the above as I said. What exactly is stored into these? Link to comment Share on other sites More sharing options...
Genusis Posted February 15, 2016 Share Posted February 15, 2016 ignore this post I thought he was using a post that had ground set as a struct to x, y and tileset. Link to comment Share on other sites More sharing options...
Xlithan Posted February 15, 2016 Author Share Posted February 15, 2016 The new maps are blank, and have been set to 30 to be the same as the old maps.Where are you getting OldMap.Tile(x, y).Ground.x from?```Type OldTileRec Ground As Long Mask As Long Anim As Long Mask2 As Long M2Anim As Long Fringe As Long FAnim As Long Fringe2 As Long F2Anim As Long Type As Byte Data1 As Long Data2 As Long Data3 As Long String1 As String String2 As String String3 As StringEnd Type```* * *Neither of those work, I just get type mismatch errors.* * ***modTypes**:```Option ExplicitPublic Const MAX_MAPS = 400Public Const MAX_MAPX = 30Public Const MAX_MAPY = 30Type OldTileRec Ground As Long Mask As Long Anim As Long Mask2 As Long M2Anim As Long Fringe As Long FAnim As Long Fringe2 As Long F2Anim As Long Type As Byte Data1 As Long Data2 As Long Data3 As Long String1 As String String2 As String String3 As StringEnd TypeType OldMapRec Name As String * 30 Revision As Long Moral As Byte Up As Long Down As Long Left As Long Right As Long Music As String BootMap As Long BootX As Byte BootY As Byte Shop As Byte Indoors As Byte Tile() As OldTileRec Npc(1 To 15) As ByteEnd TypePrivate Type EventRec Name As StringEnd TypeType NewTileDataRec x As Long y As Long Tileset As LongEnd TypeType NewTileRec Layer(1 To MapLayer.Layer_Count - 1) As NewTileDataRec Type As Byte Data1 As Long Data2 As Long Data3 As Long DirBlock As ByteEnd TypeType NewMapRec Name As String * 30 Music As String * 30 Revision As Long Moral As Byte Up As Long Down As Long Left As Long Right As Long BootMap As Long BootX As Byte BootY As Byte MaxX As Byte MaxY As Byte Tile() As NewTileRec Npc(1 To 15) As Long EventCount As Long Events() As EventRecEnd Type```**modEnums**:```Option Explicit' Layers in a mapPublic Enum MapLayer Ground = 1 Autotile Mask1 Mask2 Mask3 Mask4 Fringe1 Fringe2 Fringe3 Fringe4 ' Make sure Layer_Count is below everything else Layer_CountEnd Enum``` Link to comment Share on other sites More sharing options...
Genusis Posted February 15, 2016 Share Posted February 15, 2016 to get the Y you will need to do(Map.Tile(X, Y).Ground \ TILESHEET_WIDTH) * PIC_Yto get the X you will need to do.(Map.Tile(X, Y).Ground Mod TILESHEET_WIDTH) * PIC_Xthose based on the map tile position setup are how ground, mask and fringe are used within the old mirage based system.also sorry i thought you where converting from a map style which migth have had the variable names as ground and mask but has a x, y. I forgot the old mirage had a set integer for pixel position.oh and also ou have to set the array before you can load data into the array likeTile(0 To MAX_MAPX, 0 To MAX_MAPY) As TileRecotherwise you need to use a realloc on the tile to set it to its dimension before trying to load the data into it. =']otherwise the tile index's are none existent on either side. Link to comment Share on other sites More sharing options...
Xlithan Posted February 15, 2016 Author Share Posted February 15, 2016 Still same error```Option ExplicitSub ConvertOldMapsToNew()Dim FileName As StringDim FileName2 As StringDim m As LongDim i As LongDim F As LongDim x As Long, y As LongDim OldMap As OldMapRecDim NewMap As NewMapRec For i = 1 To MAX_MAPS FileName = App.Path & "\maps\map" & i & ".dat" FileName2 = App.Path & "\new maps\map" & i & ".dat" ' Get the old file F = FreeFile Open FileName For Binary As #F Get #F, , OldMap Close #F ' Delete the old file 'Call Kill(FileName) ReDim NewMap.Tile(0 To NewMap.MaxX, 0 To NewMap.MaxY) ' Convert NewMap.Name = OldMap.Name NewMap.Up = OldMap.Up NewMap.Down = OldMap.Down NewMap.Left = OldMap.Left NewMap.Right = OldMap.Right NewMap.BootMap = OldMap.BootMap NewMap.BootX = OldMap.BootX NewMap.BootY = OldMap.BootY For y = 0 To MAX_MAPY For x = 0 To MAX_MAPX NewMap.Tile(x, y).Layer(1).x = (OldMap.Tile(x, y).Ground \ 224) * PIC_X NewMap.Tile(x, y).Layer(1).y = (OldMap.Tile(x, y).Ground \ 224) * PIC_Y NewMap.Tile(x, y).Layer(3).x = (OldMap.Tile(x, y).Mask \ 224) * PIC_X NewMap.Tile(x, y).Layer(3).y = (OldMap.Tile(x, y).Mask \ 224) * PIC_Y NewMap.Tile(x, y).Layer(7).x = (OldMap.Tile(x, y).Fringe \ 224) * PIC_X NewMap.Tile(x, y).Layer(7).y = (OldMap.Tile(x, y).Fringe \ 224) * PIC_Y NewMap.Tile(x, y).Layer(1).Tileset = 1 NewMap.Tile(x, y).Layer(3).Tileset = 1 NewMap.Tile(x, y).Layer(7).Tileset = 1 NewMap.Tile(x, y).Type = OldMap.Tile(x, y).Type NewMap.Tile(x, y).Data1 = OldMap.Tile(x, y).Data1 NewMap.Tile(x, y).Data2 = OldMap.Tile(x, y).Data2 NewMap.Tile(x, y).Data3 = OldMap.Tile(x, y).Data3 Next x Next y ' Save the new map F = FreeFile Open FileName2 For Binary As #F Put #F, , NewMap Close #F Next iEnd Sub``` Link to comment Share on other sites More sharing options...
Genusis Posted February 15, 2016 Share Posted February 15, 2016 youforgot to redim the oldmap tiles as well. just add this to it.ReDim oldMap.Tile(0 To MAX_MAPX, 0 To MAX_MAPY)also the 224 should be 7 as that's what the original amount of tiles there where in a tile sheet originally. other wise the math will not turn out correct. since the x and y are done by tile index rather than by actual size.so math wise ground being lets say 5 5 / 7 = 0 because of rounding. * 32 = 0 5 mod 7 = 5 * 32 = 160;now with what you did 5/224 = 0 becuase of rounding but 8/224 = 0 as well when it should equal 1 after rounding.while also5 mod 224 = 5 but8 mod 224 = 8 when itnow when you do it like this with the new numbers8 mod 7 = 1 * 32 = 328 / 7 = 1 * 32 = 32which is the correct number of pixels to the tile's square. Though you can simply remove *32 to keep just the tile position then times it by 32 later that way you can make the x and y a byte Link to comment Share on other sites More sharing options...
Xlithan Posted February 15, 2016 Author Share Posted February 15, 2016 TILESHEET_WIDTH = 224 pixels for the tilesheet im using. Or do I divide 224 by 32 to get the correct TILESHEET_WIDTH?* * *Still get subscript out of range with this code.```Sub ConvertOldMapsToNew()Dim FileName As StringDim FileName2 As StringDim m As LongDim i As LongDim F As LongDim x As Long, y As LongDim OldMap As OldMapRecDim NewMap As NewMapRecReDim NewMap.Tile(0 To MAX_MAPX, 0 To MAX_MAPY)ReDim OldMap.Tile(0 To MAX_MAPX, 0 To MAX_MAPY) For i = 1 To MAX_MAPS FileName = App.Path & "\maps\map" & i & ".dat" FileName2 = App.Path & "\new maps\map" & i & ".dat" ' Get the old file F = FreeFile Open FileName For Binary As #F Get #F, , OldMap Close #F ' Delete the old file 'Call Kill(FileName) ' Convert NewMap.Name = OldMap.Name NewMap.Up = OldMap.Up NewMap.Down = OldMap.Down NewMap.Left = OldMap.Left NewMap.Right = OldMap.Right NewMap.BootMap = OldMap.BootMap NewMap.BootX = OldMap.BootX NewMap.BootY = OldMap.BootY For y = 0 To MAX_MAPY For x = 0 To MAX_MAPX NewMap.Tile(x, y).Layer(1).x = (OldMap.Tile(x, y).Ground \ 7) * PIC_X NewMap.Tile(x, y).Layer(1).y = (OldMap.Tile(x, y).Ground \ 7) * PIC_Y NewMap.Tile(x, y).Layer(3).x = (OldMap.Tile(x, y).Mask \ 7) * PIC_X NewMap.Tile(x, y).Layer(3).y = (OldMap.Tile(x, y).Mask \ 7) * PIC_Y NewMap.Tile(x, y).Layer(7).x = (OldMap.Tile(x, y).Fringe \ 7) * PIC_X NewMap.Tile(x, y).Layer(7).y = (OldMap.Tile(x, y).Fringe \ 7) * PIC_Y NewMap.Tile(x, y).Layer(1).Tileset = 1 NewMap.Tile(x, y).Layer(3).Tileset = 1 NewMap.Tile(x, y).Layer(7).Tileset = 1 NewMap.Tile(x, y).Type = OldMap.Tile(x, y).Type NewMap.Tile(x, y).Data1 = OldMap.Tile(x, y).Data1 NewMap.Tile(x, y).Data2 = OldMap.Tile(x, y).Data2 NewMap.Tile(x, y).Data3 = OldMap.Tile(x, y).Data3 Next x Next y ' Save the new map F = FreeFile Open FileName2 For Binary As #F Put #F, , NewMap Close #F Next iEnd Sub``` Link to comment Share on other sites More sharing options...
Nickpop123 Posted February 15, 2016 Share Posted February 15, 2016 Does your old maps use Mask2 or Fringe2 at all? If so:```Sub ConvertOldMapsToNew() Dim FileName As String, FileName2 As String Dim M As Long, I As Long, F As Long, X As Long, Y As Long Dim OldMap As OldMapRec Dim NewMap As NewMapRec ReDim NewMap.Tile(0 To MAX_MAPX, 0 To MAX_MAPY) As NewTileRec ReDim OldMap.Tile(0 To MAX_MAPX, 0 To MAX_MAPY) As OldTileRec For I = 1 To MAX_MAPS FileName = App.Path & "\maps\map" & I & ".dat" FileName2 = App.Path & "\new maps\map" & I & ".dat" ' Get the old file. F = FreeFile Open FileName For Binary Access Read As #F Get #F, , OldMap Close #F ' Convert. NewMap.Name = OldMap.Name NewMap.Music = OldMap.Music NewMap.Revision = OldMap.Revision NewMap.Moral = OldMap.Moral NewMap.Up = OldMap.Up NewMap.Down = OldMap.Down NewMap.Left = OldMap.Left NewMap.Right = OldMap.Right NewMap.BootMap = OldMap.BootMap NewMap.BootX = OldMap.BootX NewMap.BootY = OldMap.BootY NewMap.MaxX = MAX_MAPX NewMap.MaxY = MAX_MAPY For Y = 0 To MAX_MAPY For X = 0 To MAX_MAPX NewMap.Tile(X, Y).Layer(MapLayer.Ground).X = (OldMap.Tile(X, Y).Ground \ 7) * PIC_X NewMap.Tile(X, Y).Layer(MapLayer.Ground).Y = (OldMap.Tile(X, Y).Ground \ 7) * PIC_Y NewMap.Tile(X, Y).Layer(MapLayer.Mask1).X = (OldMap.Tile(X, Y).Mask \ 7) * PIC_X NewMap.Tile(X, Y).Layer(MapLayer.Mask1).Y = (OldMap.Tile(X, Y).Mask \ 7) * PIC_Y NewMap.Tile(X, Y).Layer(MapLayer.Mask2).X = (OldMap.Tile(X, Y).Mask2 \ 7) * PIC_X NewMap.Tile(X, Y).Layer(MapLayer.Mask2).Y = (OldMap.Tile(X, Y).Mask2 \ 7) * PIC_Y NewMap.Tile(X, Y).Layer(MapLayer.Fringe1).X = (OldMap.Tile(X, Y).Fringe \ 7) * PIC_X NewMap.Tile(X, Y).Layer(MapLayer.Fringe1).Y = (OldMap.Tile(X, Y).Fringe \ 7) * PIC_Y NewMap.Tile(X, Y).Layer(MapLayer.Fringe2).X = (OldMap.Tile(X, Y).Fringe \ 7) * PIC_X NewMap.Tile(X, Y).Layer(MapLayer.Fringe2).Y = (OldMap.Tile(X, Y).Fringe \ 7) * PIC_Y NewMap.Tile(X, Y).Layer(MapLayer.Ground).Tileset = 1 NewMap.Tile(X, Y).Layer(MapLayer.Mask1).Tileset = 1 NewMap.Tile(X, Y).Layer(MapLayer.Mask2).Tileset = 1 NewMap.Tile(X, Y).Layer(MapLayer.Fringe1).Tileset = 1 NewMap.Tile(X, Y).Layer(MapLayer.Fringe2).Tileset = 1 NewMap.Tile(X, Y).Type = OldMap.Tile(X, Y).Type NewMap.Tile(X, Y).Data1 = OldMap.Tile(X, Y).Data1 NewMap.Tile(X, Y).Data2 = OldMap.Tile(X, Y).Data2 NewMap.Tile(X, Y).Data3 = OldMap.Tile(X, Y).Data3 Next Next For X = 1 To 15 NewMap.Npc(X) = OldMap.Npc(X) Next ' Save the new map F = FreeFile Open FileName2 For Binary Access Write As #F Put #F, , NewMap Close #F NextEnd Sub```I didn't know if you have any NPCs on your old maps either, so I added a convert to that too.Also for your error, what line is it pointing to? Link to comment Share on other sites More sharing options...
Genusis Posted February 16, 2016 Share Posted February 16, 2016 @'Xlithan':> TILESHEET_WIDTH = 224 pixels for the tilesheet im using. Or do I divide 224 by 32 to get the correct TILESHEET_WIDTH?> > * * *> > Still get subscript out of range with this code.first of all 7 *32 is 224\. also make sure those maps exist in the folder before trying to read them and what line is the subscript out of range happening on exactly? if all else fails it might not be reading the data into the map so you may need to break point debug it to insure the data exists. If you need help with this i can help you. Link to comment Share on other sites More sharing options...
Xlithan Posted February 18, 2016 Author Share Posted February 18, 2016 Nickpop that wouldn't make a difference anyway.Genusis the maps exist, it loads them just fine as it sets the name value ok. It's only when it gets to the tiles part that I get the error.it's when it gets to this line:**NewMap.Tile(x, y).Layer(MapLayer.Ground).x = (OldMap.Tile(x, y).Ground \ 7) * PIC_X**and the error comes from:**OldMap.Tile(x, y).Ground** Link to comment Share on other sites More sharing options...
Nickpop123 Posted February 21, 2016 Share Posted February 21, 2016 Might I ask what engine did you use for the old maps you want to convert? Link to comment Share on other sites More sharing options...
abhi2011 Posted February 21, 2016 Share Posted February 21, 2016 If this still hasn't been fixed, I'd like to butt in and suggest a possible fix.You say the error come from **OldMap.Tile(x, y).Ground**. I think it's because you're not loading the old maps properly.```' Get the old file F = FreeFile Open FileName For Binary As #F Get #F, , OldMap Close #F```In Eclipse, the Maps are saved by dumping every variable manually and not the entire structure because there is a variable sized array (the Tile array in Map). So, you'll have to load the OldMap each variable at a time like```f = freefileopen file name for binary as #fget #f, , oldmap.Name...close #f```You can get the loading code from server side map loading, if you don't want to type it all over again.You'll have to save the map the same way, one variable at a time. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now