Re: Looping an Error Problem
I have changed the code a bit, and this works better, however it doesn't solve my problem.
Code:
Public Function ChangeTile(ByVal Index As Integer, ByVal ChangeDirection As Integer)
Dim RndImg As Integer
Dim Xval As Integer
Dim Yval As Integer
Dim Error As Byte
On Error GoTo Cleanup
Xval = Index Mod Map.SizeX
Yval = Index \ Map.SizeX
Error = 1
If ChangeDirection > 0 Then
Map.Tile(Xval, Yval).Type = Map.Tile(Xval, Yval).Type + 1
ElseIf ChangeDirection < 0 Then
Map.Tile(Xval, Yval).Type = Map.Tile(Xval, Yval).Type - 1
End If
frmMain.MapTile(Index).Picture = LoadPicture("C:\Documents and Settings\Mike\My Documents\RPG Game\Images\MAP" & Map.Tile(Xval, Yval).Type & "-0.gif")
ChangeDirection = 0
Retry:
On Error GoTo Cleanup
Error = 2
RndImg = Random(0, 3)
frmMain.MapTile(Index).Picture = LoadPicture("C:\Documents and Settings\Mike\My Documents\RPG Game\Images\MAP" & Map.Tile(Xval, Yval).Type & "-" & RndImg & ".gif")
Exit Function
Cleanup:
Err.Clear
If Error = 1 Then
Map.Tile(Xval, Yval).Type = 0
frmMain.MapTile(Index).Picture = LoadPicture("C:\Documents and Settings\Mike\My Documents\RPG Game\Images\MAP" & Map.Tile(Xval, Yval).Type & "-0.gif")
GoTo Retry
ElseIf Error = 2 Then
GoTo Retry
End If
End Function
Re: Looping an Error Problem
Instead of randomizing the file name like here
frmMain.MapTile(Index).Picture = LoadPicture("C:\Documents and Settings\Mike\My Documents\RPG Game\Images\MAP" & Map.Tile(Xval, Yval).Type & "-" & RndImg & ".gif")
Use Dir function (or FSO, or FiliListBox) to load all files to a list, then randomize a number in the range of the number of items in the list and based on that use a file from the list.
Re: Looping an Error Problem
It's quite a good idea, I like it.
I've used filelistbox's before, one thing I don't know how to do is to specify the specific filename as well, since showing the directory will show lots of images, all but 1 or 2 will be just clutter.
for instance I'll need to specify that i the filename it will be
"Map" & Map.Tile(Xval, Yval).Type & "-"
which I'm sure it's not hard, however something which I don't even know how to do, so I doubt the answer will be that obvious.
I'll look it up now, however if you know the answer, mind just telling me.
thanks :)
Re: Looping an Error Problem
actually don't worry, I made a function which searched for any string you put in, used a loop and added 1 to the function every time it found one.
thanks for the idea. :D