Page 1 of 2
Posted: Sun May 05, 2002 1:12 am
by BackupUser
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)
Posted: Sun Sep 01, 2002 2:44 pm
by BackupUser
Restored from previous forum. Originally posted by merendo.
Can you help me?
Cu @ll, merendo
--
I've been hiding - What am I hiding from???
Posted: Sun Sep 01, 2002 2:55 pm
by BackupUser
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:
Code: Select all
if mousehit and hitonce1
; this only gets executed once
hitonce=1
endif
Posted: Sun Sep 01, 2002 3:31 pm
by BackupUser
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???
Posted: Sun Sep 01, 2002 3:55 pm
by BackupUser
Restored from previous forum. Originally posted by freak.
> Protected hitbefore
This makes hitbefore always be 0 when the Procedure is called, change it to:
Shared hitbefore
Posted: Sun Sep 01, 2002 4:08 pm
by BackupUser
Restored from previous forum. Originally posted by 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
see what your problems were?
regards,
traumatic
Posted: Sun Sep 01, 2002 4:11 pm
by BackupUser
Restored from previous forum. Originally posted by traumatic.
Originally posted by freak
oh, i didn't see your reply...
merendo: you also left your procedure before actually setting hitbefore=1
--------
good programmers don't comment their code. it was hard to write - should be hard to read!
Posted: Sun Sep 01, 2002 5:27 pm
by BackupUser
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().
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
Cu @ll, merendo
--
I've been hiding - What am I hiding from???
Posted: Sun Sep 01, 2002 5:33 pm
by BackupUser
Restored from previous forum. Originally posted by traumatic.
as i already tried to explain:
you're leaving your procedure before actually setting 'hitbefore' to 1.
you wrote:
ProcedureReturn 1
hitbefore = 1
but of course it has to be:
hitbefore = 1
ProcedureReturn 1
see?
Posted: Sun Sep 01, 2002 6:21 pm
by BackupUser
Restored from previous forum. Originally posted by merendo.
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
Cu @ll, merendo
--
I've been hiding - What am I hiding from???
Posted: Sun Sep 01, 2002 6:30 pm
by BackupUser
Restored from previous forum. Originally posted by traumatic.
what is it, you don't understand?
as soon as ProcedureReturn gets executed your are LEAVING the procedure.
procedurereturn 1 ; now leaving the procedure
hitbefore=1 ; this line NEVER gets executed
still no clue? let me now

Posted: Sun Sep 01, 2002 7:12 pm
by BackupUser
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???
Posted: Sun Sep 01, 2002 7:26 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Does that mean, that ALL code after the ProcedureReturn won't be executed?
As soon as the ProcedureReturn command is executed it exits the procedure, take a look at this:
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
Posted: Sun Sep 01, 2002 7:55 pm
by BackupUser
Restored from previous forum. Originally posted by traumatic.
Originally posted by merendo
Sorry, I didn't know about this.
no deal. we're all here to learn
--------
good programmers don't comment their code. it was hard to write - should be hard to read!
Posted: Sun Sep 01, 2002 8:43 pm
by BackupUser
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???