Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   Problem whit mouse methods (http://www.alice.org/community/showthread.php?t=9379)

djslater107 10-13-2020 07:37 AM

Use while mouse is clicked on something
 
1 Attachment(s)
You have set this up well, actually, but another response pointed out that Alice 2 puts every event into a queue and will process them one after another no matter how long the wait is. (This is an issue that we have fixed in Alice 3, where you are able to use a setting to ignore multiple mouse-clicks)

Try this in Alice 2.
1) Right click on the "When mouse is clicked on... " tile
2) Select "Change to..."
3) Select "While mouse the mouse is pressed on something"
4) The tile will change so that you now have a Begin, a During, and End option.
5) Put your method call in either Begin or End, not During.

Begin and End execute the method one time either when you start to press the mouse or when you release the mouse. During will execute the method continuously as long as the mouse button is held.

This should work for you. I have attached a sample project as an illustration. Let m know if you have any other questions.

Don Slater
Alice Project



[QUOTE=facup94;50487]I have a problem whit mouse events.
When i click multiple times, the method run multiple times too. But i want the method activates only when is not working at this time.
Sorry for my english.
I looking something like:
if (method is running = true)
do nothing
else
do something

But when i click multiple times this method continues running after i stop click (number of times i click).[/QUOTE]

djslater107 10-13-2020 07:50 AM

Use the while mouse is pressed on something event
 
1 Attachment(s)
You have done a good job trying to solve this problem, but as was pointed out, Alice 2 puts events into a Queue and will still fire them in sequence no matter how long you Wait. (Alice 3 addresses this problem with an option to ignore multiple clicks on mouse events, but that does not help you here.)

However, it is possible to convert the "When mouse is clicked on..." event to a "while the mouse is pressed..." event, which will solve the problem.

1) Right-click on the "When mouse is clicked on... " tile
2) Select "change to..."
3) Select "While the mouse is pressed on..."
4) Select your mouse-press target
5) You now have three options Begin, During, and End. Add your method call to either Begin or End, not During. Your gun should now only fire once either when you click the mouse, or when you release the mouse (depending on which option you chose.

Begin responds to the mouse-press one time when you start to press the mouse button

End responds to the mouse-press one time when you release the mouse button

During continually responds to the mouse-press as long as you are holding the mouse button.

I have attached a demo world "bunnyhop.a2w" that illustrates this event.

Please let me know if you have any questions.

Don Slater
Alice Project


All times are GMT -5. The time now is 12:04 AM.

Copyright ©2022, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.