quick question

Blitz3D Forums/Blitz3D Beginners Area/quick question

chwaga(Posted 2008) [#1]
the grabbing (pick up an item and move it to a different slot) part of my inventory system is as follows:

For item.genericitem = Each genericitem
			Select item\slot 
				Case 1
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)-159, (displayheight/2)-233, 160, 160) And MouseHit(1) Then hold = True
				Case 2
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)+1, (displayheight/2)-233, 160, 160) And MouseHit(1) Then hold = True
				Case 3
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)-159, (displayheight/2)-73, 160, 160) And MouseHit(1) Then hold = True
				Case 4
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)+1, (displayheight/2)-73, 160, 160) And MouseHit(1) Then hold = True
				Case 5
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)-159, (displayheight/2)+87, 160, 160) And MouseHit(1) Then hold = True
				Case 6
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)+1, (displayheight/2)+87, 160, 160) And MouseHit(1) Then hold = True
			End Select
			If hold = True Then
				item\held = True
				hold = False 
			EndIf
			If item\held = True Then
				DrawImage item\image, MouseX(), MouseY()
				If Not MouseDown(1) Then
					item\held = False
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)-159, (displayheight/2)-233, 160, 160) Then item\slot = 1
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)+1, (displayheight/2)-233, 160, 160) Then  item\slot = 2
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)-159, (displayheight/2)-73, 160, 160) Then item\slot = 3
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)+1, (displayheight/2)-73, 160, 160) Then item\slot = 4
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)-159, (displayheight/2)+87, 160, 160) Then item\slot = 5
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)+1, (displayheight/2)+87, 160, 160) Then item\slot = 6
				EndIf
			EndIf
		Next


the problem is that when i run this, and try to grab an item using the left click and hold, most of the times it will not grab. On rare occasions it will grab the item, and everything will work, but most of the times this does not happen. ideas?

any help = thank you


chwaga(Posted 2008) [#2]
update: partially fixed it, it was the using of mousehit(1) in place of mousedown(1). However, using mousedown causes problems with dragging an item over another item makes you pick that up too. This is fixed with utilizing the hold variable. Now, for completely other reasons, dragging one of two items to another slot (not going over the other) causes both to move. code:

For item.genericitem = Each genericitem
			If hold = False Then 
				Select item\slot 
					Case 1
						If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)-159, (displayheight/2)-233, 160, 160) And MouseDown(1) Then hold = True
					Case 2
						If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)+1, (displayheight/2)-233, 160, 160) And MouseDown(1) Then hold = True
					Case 3
						If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)-159, (displayheight/2)-73, 160, 160) And MouseDown(1) Then hold = True
					Case 4
						If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)+1, (displayheight/2)-73, 160, 160) And MouseDown(1) Then hold = True
					Case 5
						If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)-159, (displayheight/2)+87, 160, 160) And MouseDown(1) Then hold = True 
					Case 6
						If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)+1, (displayheight/2)+87, 160, 160) And MouseDown(1) Then hold = True
				End Select
			EndIf 
			If hold = True Then
				item\held = True
			EndIf
			If item\held = True Then
				DrawImage item\image, MouseX(), MouseY()
				If Not MouseDown(1) Then
					item\held = False
					hold = False 
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)-159, (displayheight/2)-233, 160, 160) Then item\slot = 1
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)+1, (displayheight/2)-233, 160, 160) Then  item\slot = 2
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)-159, (displayheight/2)-73, 160, 160) Then item\slot = 3
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)+1, (displayheight/2)-73, 160, 160) Then item\slot = 4
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)-159, (displayheight/2)+87, 160, 160) Then item\slot = 5
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)+1, (displayheight/2)+87, 160, 160) Then item\slot = 6
				EndIf
			EndIf
		Next



Rob Farley(Posted 2008) [#3]
This might help you....

http://www.blitzbasic.com/codearcs/codearcs.php?code=2001


chwaga(Posted 2008) [#4]
does exactly what i do, but mine doesn't quite work..


Rob Farley(Posted 2008) [#5]
does exactly what i do, but mine doesn't quite work..
Then one might argue it doesn't do exactly what yours does.


chwaga(Posted 2008) [#6]
shut up :P


chwaga(Posted 2008) [#7]
narrowed the bug down to this:

If item\held = True Then
				DrawImage item\image, MouseX(), MouseY()
				If Not MouseDown(1) Then
					item\held = False
					hold = False 
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)-159, (displayheight/2)-233, 160, 160) Then item\slot = 1
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)+1, (displayheight/2)-233, 160, 160) Then  item\slot = 2
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)-159, (displayheight/2)-73, 160, 160) Then item\slot = 3
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)+1, (displayheight/2)-73, 160, 160) Then item\slot = 4
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)-159, (displayheight/2)+87, 160, 160) Then item\slot = 5
					If RectsOverlap (MouseX(), MouseY(), 1, 1, (displaywidth/2)+1, (displayheight/2)+87, 160, 160) Then item\slot = 6
				EndIf
			EndIf

for some reason it's placing BOTH of two objects in the inventory to the selected spot