Alice Community  

Go Back   Alice Community > Alice 3 > How Do I?

Reply
 
Thread Tools Display Modes
Exception with AddMouseButtonListener
Old
CraigGraham
Junior Member
 
Status: Offline
Posts: 6
Join Date: Oct 2011
Location: UK
Default Exception with AddMouseButtonListener - 10-30-2011, 07:35 AM

We're new to Alice, have gone straight into 3.0 beta and are having issues that may either be newbie trouble or a bug in beta.

Trying to get a bunch of robots to move towards a target, and when each robot is clicked by the mouse it jumps back a way.

To do this, we've defined an array of the robots, and for each robot 'm' in the array we do m.AddMouseButtonListener, and specify an action m.MoveAwayFrom the target.

Then, in a seperate block, for each robot we have a While(true) that moves the robot towards the target and then has a delay, so they keep inching forward.

If we just have the move loop on its own things are fine, the robots move towards the target step by step. If we have the AddMouseButtonListener block, either as part of a single For Each loop that does everything or as part of an initial For Each loop, there's repeated exceptions fired when the program runs.

Is there something obvious we're doing wrong here? Are we only allowed mouse button listeners on one object? I've done a search on the forum for AddMouseButtonListener and had no hits.
   
Reply With Quote
Old
CraigGraham
Junior Member
 
Status: Offline
Posts: 6
Join Date: Oct 2011
Location: UK
Default 10-31-2011, 12:09 PM

Ah. There was a vaguely obvious thing.

If you have

for (MyRobot m:robots)
{
m.addMouseButtonListener ( whatever )
}

the variable m isn't valid in "whatever". It seems you have to use e.getModelAtMouseLocation instead. But e isn't available from the list of things you can get Procedures and Functions for, as far as I can see, so you have to drop in the procedure you want from some other object- which of course would logically be "m", and then you have to use the drop down list in the code window to change "m" to "e" and pick the right function.

Replied to self because nobody else seemed to be and it might be useful to someone at some point
   
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



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