Problem with mouse....

Blitz3D Forums/Blitz3D Beginners Area/Problem with mouse....

Valgar(Posted 2004) [#1]
Hallo.
I have a simple problem (among many others much bigger...).
I have a code that check if a button is pressed.
I do this in this manner:
first i check if the left mouse button is pressed and second if the image under the mouse pointer is overlapping the image of the button.
The strange thing is that if i use mousebutton(1) the code don't work at all...so i change with mousebutton(2)....
The second strange thing is if i use mousehit(2) nothing happen!
I have to use mousedown(2)....but if i use this i don't have the same effect i search (every time i check i want to create a object...and if i use mousedown many object are created!).
I have many many lines of codeabove this small ones...and i have similar problems with various mousebutton!
If i use the key nothing go wrong...but i want to use the mouse to make every action,so the user don't waste time to learn all the buttons.
What could possibly be the problem?
Another question...this is a complex one without see the code itself...but i try to explayn the effect.
My code is an application to create "path points" to use in game dev...to make object move and so on.
I have a simple interface made by myself(wich i interact in the manner i described above) that have the possibility to:make new path,load saved path,try path,save path,cancel path,exit program.
If i create a new path.....all go ok until i click the "cancel button".....i use array to store the position of the button (made with the esc key because the mouse button don't work[see above...])so every click of the key i store information of the coordinates of the cursor....but if i click cancel....i want to reset the array and to continue to follow the position of the mouse until i click again.
But if i click cancel...and repeat the creation process....the FIRST nodes coordinates is the coordinates that the mouse have when i click cancel!
I don't know how to restore all at the beginning!
I use array to store data and types to set path nodes...so is array within types.
Cancel button goes trough all types and cancel all created object....and set the array of nodes to 0.
I also don't know how to change to "path that i create on the fly" and "path that i have previously loaded"....
So if i load a path and i create a new one...the object still continue to follow the loaded one and viceversa if i create and after i load a new one....
I have tried to make "trigger" variable to set the button pressed but nothing....always the same problems!
I think the bigger problem is the one of the mouse button (i have tried to use flushmouse but nothing...).
If there's anyone who whant to see the code.....is a little big and commented in italian....and not too well writed!
Thanks in advance!
(i also have tried to use xlnt gui but don't know how to interact with buttons created..argh)


Valgar(Posted 2004) [#2]
I think that i have founded a warkaround methods to reset the first coordinates (i have inserted two declaration when i press the create button that assign mousex and mousey until i press the button to set the path points...) but i have also founded that some of my code works with mousedown and other works with mousehit....
and is bad because the function that i want to use mousehit works only with mousedown :(
why this difference???


eBusiness(Posted 2004) [#3]
If you in a loop call:

a=Mousehit(1)
b=Mousehit(1)
c=Mousehit(1)

then a will be 1 if you hit the mousekey, b and c will be 0, as MouseHit works so that it will be reset when you call it. The simple way to make such code work is to have a variable where you once per loop store MouseHit(1):

mouse1=MouseHit(1)
If mouse1 Then etc...

I have no idea why you can only make the right mouse button work.

For the rest of your problems, work over it in a logical way, step for step, what happens, what array values are cleared, what is the array pointer set to?


Valgar(Posted 2004) [#4]
Yes you have understand the problem quite correctly!
I use mousehit instead of mousedown because i have a variable assigned to mousehit that create object,so if i use mousedown instead the variable create many object!
I also understand that calling mousehit in a rows don't work, and it's my problem.
But i don't understand your solution....
Example:
[code]
a=mousehit ;this create an object
b=mousehit ;this exit program
c=mousehit ;this start the animation

;main
if a=1
;create object
a=0
endif

if b=1
;exit program
b=0
endif

if c=1
;start animation
c=0
endif

;end main
[\code]

For the reason that you described me b and c are always 0 if called in a row after a=mousehit....
I don't know what do you intend to have a variable where i store mousehit....


Rob Farley(Posted 2004) [#5]
You realise you can quite easily solve your first problem by doing

if mousedown(1) then

do stuff

repeat
until mousedown(1)=false
endif

so you have to release the button before any code will continue


Valgar(Posted 2004) [#6]
Excuse me...i'm an idiot :P
I have inserted a simple mouse1=mousehit(1) at the start of my main and modified the variable as well and now all works very well!
Many thanks.
About the other problem....i think that for my skill as a programmer i have made a code too big....and now i don't know where's the bug :P
But i have finded a workaround that work (but i suspect that i have wasted other time-machine as well hehe) using a simple " if bla bla bla then goto .exit".


eBusiness(Posted 2004) [#7]
I meant like this:


;main
a=mousehit

if a=1
;create object
endif

if a=1
;exit program
endif

if a=1
;start animation
endif

;end main



Sir Gak(Posted 2004) [#8]
Valgar: you wrote:
About the other problem....i think that for my skill as a programmer i have made a code too big....and now i don't know where's the bug :P

Tup for troubleshooting code. When writing code, change one thing at a time, so that if a problem occurs, you know at what point the problem occurred. When you have code that is already too big and are not sure how to track down the problem, try isolating code segments and try them one at a time. For example, put some blank lines before and after a segment you want to isolate. Use that old fashion command GOTO, and then a label at the point you want it to goto. You can thereby jump over sections, and fine tune which segments you want to try out independent from the rest of the code. Hope this helps.


Valgar(Posted 2004) [#9]
Yes helps indeed!
I avoid the "goto" because i have read (don't remember where...)that are less faster than function....but in this case are indeed valuable.
I have finded the problem,but don't figured out how to avoid it......it's so a smallish bug that i think nobody see it :P
Now the next step is create precalculated routine to speed up the program when i use sin/cos/atan ecc ecc.
Thanks for the reply.