BlitzPlus: mouse trouble

BlitzPlus Forums/BlitzPlus Beginners Area/BlitzPlus: mouse trouble

Darkseid2.0(Posted 2014) [#1]
I'm playing around with the mouse functions and for some unknown reason MouseX and MouseY refuses to work. When you click any where on the screen and hold the left mouse button the box should move with the mouse. But if MouseX and MouseY refuse to work then the box wont move. If any of you can see an error I'm missing then please point it out.

here's the code I'm not sure if I'm doing something wrong or not:

Include "keyboard.bb"

Type Tbox
Field x#
Field y#
Field w#
Field h#
End Type

Type Tmouse
Field x#
Field y#
End Type

Graphics 800, 600,0,2
SetBuffer BackBuffer()

mymouse.Tmouse = New Tmouse
box.tbox = New tbox

box\x = 100
box\y = 100
box\w = 200
box\h = 200

While Not KeyHit(K_ESC)

Cls

mymouse\x = MouseX
mymouse\y = MouseY

Text 0,0, "Hello"
Text 0,10, MouseDown(1)
Text 0,20, mymouse\x
Text 0,30, mymouse\y

If MouseDown(1) Then
box\x = box\x + mymouse\x
box\y = box\y + mymouse\y
End If

Rect box\x, box\y, box\x + box\w, box\y + box\h,0

Flip

Wend

End


Rob the Great(Posted 2014) [#2]
Hello,

For future reference, you can include the (code) and (/code) tags in your post to have your code formatted nicely. Just replace each () with a [] and it will work, like so:
;Your code here!


To answer your question, keep in mind that every function which returns a value needs to have a pair of () at the end of the function. Otherwise the function will return nothing. This is why the MouseX() and MouseY () are not working. So your code should become:

Include "keyboard.bb"

Type Tbox
	Field x#
	Field y#
	Field w#
	Field h#
End Type

Type Tmouse
	Field x#
	Field y#
End Type

Graphics 800, 600,0,2
SetBuffer BackBuffer()

mymouse.Tmouse = New Tmouse
box.tbox = New tbox

box\x = 100
box\y = 100
box\w = 200
box\h = 200

While Not KeyHit(K_ESC)

	Cls

	mymouse\x = MouseX()
	mymouse\y = MouseY()
	
	Text 0,0, "Hello"
	Text 0,10, MouseDown(1)
	Text 0,20, mymouse\x
	Text 0,30, mymouse\y
	
	If MouseDown(1) Then
		box\x = box\x + mymouse\x
		box\y = box\y + mymouse\y
	End If
	
	Rect box\x, box\y, box\x + box\w, box\y + box\h,0
	
	Flip
	
Wend

End



Floyd(Posted 2014) [#3]
Functions, which return a value, must be used with parentheses, e.g. MouseX().


Rob the Great(Posted 2014) [#4]
Wow, that was strange. I posted this response on the B3D forum and it ended up here somehow. I haven't programmed in BlitzPlus, so I don't know if the same fix will work. I assume it's the same.


TomToad(Posted 2014) [#5]
First, put your code in between code tags when posting to the forum [code][/code]. It will make your code easier to read. Second, you need to put parentheses after the MouseX() and MouseY() commands.


Darkseid2.0(Posted 2014) [#6]
Thank for the help. =^.^=