@ Somarl
Give this a go and see if it does what you want. I've copied some of the code I used in my RTS and cut it down to your needs. Here's how you use it:
1) Before you can use it, you need to call
InitMouse() once.
2) You have to call
ControlMouse() once every loop.
3)
uMouse.click returns:
--
1 if the mouse was
just clicked
--
2 if the mouse is
being held down
--
3 if the mouse was
just released
In your case, you are looking for when the mouse was just clicked, so you have to check for a 1 (which you are doing here):
Mousebox(566, 100, 630, 132, 1)
Then, instead of checking mouseclick(), I replaced it with this:
If MouseX() >= x1 AND MouseY() >= y1 AND MouseX() <= x2 AND MouseY() <= y2 AND uMouse.click = Button
Here's the entire code:
rem Initialize mouse, just as we discussed
InitMouse()
Load Image "BuildButton.jpg", 1
Load Image "House.jpg", 2
Sprite 1, 0, 0, 2
Hide Sprite 1
Offset Sprite 1, 64, 64
Do
Cls
Paste Image 1, 566, 100
If Mousebox(566, 100, 630, 132, 1) = 1
Print "Clicked"
BuildingFlag = 1
EndIf
If BuildingFlag = 1
Paste Sprite 1, MouseX(), MouseY()
If MouseClick() = 1 And Flag = 1
HouseOwned = 1
BuildingFlag = 0
HouseX = MouseX()
HouseY = MouseY()
EndIf
EndIf
DisplayBuildings()
rem update mouse
ControlMouse()
Loop
Function DisplayBuildings()
If HouseOwned = 1
Paste Sprite 1, HouseX, HouseY
EndIf
Endfunction
Function Mousebox(x1, y1, x2, y2, Button)
A = 0
If MouseX() >= x1 AND MouseY() >= y1 AND MouseX() <= x2 AND MouseY() <= y2 AND uMouse.click = Button
A = 1
Endif
Endfunction A
rem ---------------------------------------------------------------------------
rem Mouse click controls
rem ---------------------------------------------------------------------------
rem mouse UDT
type MouseVT
oldclick as integer
currentclick as integer
click as integer
endtype
rem ---------------------------------------------------------------------------
rem initialize
rem ---------------------------------------------------------------------------
function InitMouse()
global uMouse as MouseVT
endfunction
rem ---------------------------------------------------------------------------
rem Updates the mouse values
rem ---------------------------------------------------------------------------
function ControlMouse()
rem process mouse clicks
uMouse.oldclick=uMouse.currentclick
uMouse.currentclick=mouseclick()
if uMouse.oldclick=0 and uMouse.currentclick=0 then uMouse.click=0
if uMouse.oldclick=0 and uMouse.currentclick=1 then uMouse.click=1
if uMouse.oldclick=1 and uMouse.currentclick=1 then uMouse.click=2
if uMouse.oldclick=1 and uMouse.currentclick=0 then uMouse.click=3
endfunction
Quote: "Ummmm, what? All he needs is a simple flag. "
That's exactly what my code does.
I'm not sure what it's called in the IT world, but with micro controllers and in electronics, button signals have 4 states:
-not pressed
-just pressed
-is pressed
-just released
And most things are triggered on a "positive edge" (just pressed), because the signal is rising. Hence the name "positive edge detection". There are also applications where things are triggered when a button is released, so you'd need to detect a negative edge.
In my code I posted, MouseClick_positive would need to be checked if you wanted to detect a positive edge, MouseClick_normal would return the normal "mouseclick()" value, and MouseClick_negative would need to be checked to detect a negative edge.
old_MouseClick = current_MouseClick
current_MouseClick = mouseclick()
MouseClick_positive = (not old_MouseClick and current_Mouseclick)
MouseClick_normal = (old_MouseClick and current_MouseClick)
MouseClick_negative = (old_MouseClick and not current_MouseClick)
TheComet