MouseHit()
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by merendo.
Hello Guys and Girls;
Question: Is there in PB also a command working like MouseHit() in BlitzBasic? When the mousebutton is pushed, the function should return the pushed-value only once.
Thanks, merendo
We always need to hear both sides of the story (by Phil Collins)
Hello Guys and Girls;
Question: Is there in PB also a command working like MouseHit() in BlitzBasic? When the mousebutton is pushed, the function should return the pushed-value only once.
Thanks, merendo
We always need to hear both sides of the story (by Phil Collins)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by traumatic.
why don't you simply set a variable after the mouseclick has occured and check if the value is like you set it?
pseudocode:
why don't you simply set a variable after the mouseclick has occured and check if the value is like you set it?
pseudocode:
Code: Select all
if mousehit and hitonce1
; this only gets executed once
hitonce=1
endif
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by merendo.
Already tried. Doesn't work:
Procedure MouseHit(button)
Protected hitbefore
If MouseButton(button) And hitbefore = 0
ProcedureReturn 1
hitbefore = 1
EndIf
If MouseButton(button) = 0 : hitbefore = 0 : ProcedureReturn 0: EndIf
EndProcedure
Cu @ll, merendo
--
I've been hiding - What am I hiding from???
Already tried. Doesn't work:
Procedure MouseHit(button)
Protected hitbefore
If MouseButton(button) And hitbefore = 0
ProcedureReturn 1
hitbefore = 1
EndIf
If MouseButton(button) = 0 : hitbefore = 0 : ProcedureReturn 0: EndIf
EndProcedure
Cu @ll, merendo
--
I've been hiding - What am I hiding from???
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by traumatic.
of course it does
see what your problems were?
regards,
traumatic
of course it does
Code: Select all
Procedure MouseHit(button)
Shared hitbefore
If MouseButton(button) And hitbefore = 0
hitbefore = 1
ProcedureReturn 1
EndIf
EndProcedure
; mainloop
Repeat
ExamineMouse()
If MouseHit(1) = 1
Debug "mouse hit once!"
EndIf
Forever
regards,
traumatic
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by merendo.
See this code: It doesn't work. The 1 is always displayed when hitting the mouse, as if it is mousebutton().
Cu @ll, merendo
--
I've been hiding - What am I hiding from???
See this code: It doesn't work. The 1 is always displayed when hitting the mouse, as if it is mousebutton().
Code: Select all
InitMouse()
InitSprite()
Procedure MouseHit(button)
Shared hitbefore
If MouseButton(button) And hitbefore = 0
ProcedureReturn 1
hitbefore = 1
EndIf
If MouseButton(button) = 0 : hitbefore = 0 : ProcedureReturn 0: EndIf
EndProcedure
If OpenScreen(640,480,16,"test")
Repeat
ExamineMouse()
ClearScreen(0,0,0)
StartDrawing(ScreenOutput())
Locate(MouseX(),MouseY())
DrawText(Str(MouseHit(1)))
StopDrawing()
FlipBuffers()
Until MouseButton(2)
EndIf--
I've been hiding - What am I hiding from???
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by merendo.
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
Cu @ll, merendo
--
I've been hiding - What am I hiding from???
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
Cu @ll, merendo
--
I've been hiding - What am I hiding from???
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by merendo.
Sorry, I didn't know about this. I always thought, ProcedureReturn is as if a normal command, but I didn't know, that it quits the procedure. Does that mean, that ALL code after the ProcedureReturn won't be executed?
Cu @ll, merendo
--
I've been hiding - What am I hiding from???
Sorry, I didn't know about this. I always thought, ProcedureReturn is as if a normal command, but I didn't know, that it quits the procedure. Does that mean, that ALL code after the ProcedureReturn won't be executed?
Cu @ll, merendo
--
I've been hiding - What am I hiding from???
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
As soon as the ProcedureReturn command is executed it exits the procedure, take a look at this:Does that mean, that ALL code after the ProcedureReturn won't be executed?
Code: Select all
Procedure.l TestProc(foo.l)
Shared bar.l
If foo > 0
bar = 0
ProcedureReturn 1 ; Here the procedure exits immidiately, no line of code
; in the procedure is executed after this!
bar = 1 ; so this line is a total waste of typing effort
Else
bar = 1
ProcedureReturn 2 ; See above, same goes here...
EndIf
; so putting lines of code here will not be good as they will never be executed!
EndProcedure
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by merendo.
@Pupil: OK!!! Thanks, I guess I have to say: procedurereturn result$ and only change the vari result$
@traumatic: You don't know how right you are. Especially me!!!
Good night @ll
Cu @ll, merendo
--
I've been hiding - What am I hiding from???
@Pupil: OK!!! Thanks, I guess I have to say: procedurereturn result$ and only change the vari result$
@traumatic: You don't know how right you are. Especially me!!!
Good night @ll
Cu @ll, merendo
--
I've been hiding - What am I hiding from???