'Memory Access Violation"

Blitz3D Forums/Blitz3D Beginners Area/'Memory Access Violation"

The problem is your use of the command MouseHit().

Ironically, this is kinda similar to the image loading problem you encountered in the sense that you should only be doing it once per loop.

You see, there is a buffer that holds the number of times that the mouse was hit since the last time you called the MouseHit() command. And every time you check that buffer with the MouseHit() command, the buffer is cleared (zeroed).

In your code you check for a MouseHit() on this line:
If ImagesOverlap(pointer, pointer_x, pointer_y, Next1, 102, 582) And MouseHit(1) Then currenttile=currenttile+1
which is fine BUT then you check for it AGAIN on this line:
If ImagesOverlap(pointer, pointer_x, pointer_y, previous, 20, 582) And MouseHit(1) Then currenttile=currenttile-1
Now, since calling the MouseHit() command the first time cleared the MouseHit buffer, the second call to it will give you an incorrect result of zero hits. Do you understand this?

To avoid this from happening you should only make ONE call to MouseHit() per loop of your game and save that value in a variable. Then you can check the value of that variable as many times as you want in your loop without it 'magically' changing value.

At my Programming Tutorial, I give a few examples of how to do this in my code examples. Take a look. Here is one example:
  wkey = KeyDown(17)				;collect user input
  skey = KeyDown(31)				;It's a good practice to collect these inputs only once
  akey = KeyDown(30)				;per loop.  This will prevent odd behaviors from happening,
  dkey = KeyDown(32)				;for instance if the state of a key changes between multiple
  mouse1 = MouseHit(1)				;checks of that key while still in the same loop.

;...later...
  If mouse1 = True				;check if left mouse button was pressed
    ;blah, blah, blah



Also, just to be helpful, really long lines of code like this:
If ImagesOverlap(pointer, pointer_x, pointer_y, Next1, 102, 582) Then DrawImage next2, 102, 582
If ImagesOverlap(pointer, pointer_x, pointer_y, Next1, 102, 582) And Mouse1 Then currenttile=currenttile+1
If currenttile > 4 Then currenttile = 0	
If Not ImagesOverlap(pointer, pointer_x, pointer_y, next1, 102, 582) Then DrawImage Next1, 102, 582
where you are using redundant If arguments can be reduced to a lot less code. This not only helps make it more readable, but actually makes it faster too since you are only performing the redundant check once.
Try writing it like this (it works exactly the same way):
If ImagesOverlap(pointer, pointer_x, pointer_y, Next1, 102, 582)
	DrawImage next2, 102, 582
	If Mouse1 Then currenttile = currenttile + 1
	If currenttile > 4 Then currenttile = 0	
Else
	DrawImage Next1, 102, 582
EndIf
You see, we reduced the three ImagesOverlap checks to only one check.