(SOLVED) Trouble with detecting whether the mouse is over a particular object

Started by Snake, Thu 28/05/2009 15:22:28

Previous topic - Next topic

Snake

Hello once again,

I've a GUI that switches on while holding down the right mouse button.

This works with no problem. Displaying an integer within it's label works fine as well.

But, I want to detect when the ouse is over particular objects and come on, but I'm not getting anywhere.

Here's the code:
Code: ags

if (Mouse.IsButtonDown(eMouseRight)==true){
  if (Object.GetAtScreenXY(mouse.x, mouse.y)==object[20]){
    GuyDescr.Text=String.Format("%d",cputankhp);
    gfloater.X=mouse.x;
    gfloater.Y=mouse.y-20;
    gfloater.Visible=true;
    }
  else {}
}


I've also tried GetLocationType but that isn't working for me as well.

What am I missing to include? Or am I even heading in the right direction?

Thanks in advance,

--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

Khris

What doesn't work?

Try:
Code: ags
  if (Mouse.IsButtonDown(eMouseRight)) {
    Object*o = Object.GetAtScreenXY(mouse.x, mouse.y);
    if (o != null) Display("%d", o.ID);
  }

This should display the ID of the object under the mouse.

Snake

Hmm, that's not displaying anything either... I wonder what's going on?


Sorry it took so long to reply. I had taken little Sampson Hinkleberry (my daughter, Sam) to Story Hour at the library.

//--EDIT--//

Wait a minute... I think I'm on to something...
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

Snake

I think I've found the problem but I don't know how to solve it.

It's definately not the code. It has something to do with the objects.

The code works for objects 1-10 but not for objetcs 11-20. There's no difference between any of these objects in the properties tab, since, I was thinking maybe it was something small like making them not clickable. But they are all the same.

Any ideas of what this could be?
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

Khris

Them being not clickable will indeed prevent them from being registered by Object.GetAtScreen.XY (which has its advantages but can also be confusing).
I'm not sure whether you said they're non-clickable but I can't think of any other explanation at the moment.

GarageGothic

Yes, I would also guess it's the Clickable property that is playing tricks on you. As a workaround, you could do something like this:

Code: ags
bool objclick[];
objclick = new bool[Room.ObjectCount];
int objcount;
while (objcount < Room.ObjectCount) {
  objclick[objcount] = object[objcount].Clickable;
  object[objcount].Clickable = true;
  objcount++;
  }

//PUT YOUR CODE HERE
//THEN, AFTER YOUR SCRIPT HAS FINISHED:

while (objcount > 0) {
  objcount--;
  object[objcount].Clickable = objclick[objcount];
  }


Unless the Clickable status of the object changes while in a room, you could optimize a bit by declaring the "bool objclick[];" array outside the function and store the Clickable status during the player enters room event. But I doubt you would experience any real slowdown from using my script, so it's not really worth the effort in my opinion.

Snake

Heh - I knew it had to do with them being clickable. When I started making this game, which wasn't actually ever going to be anything (but of course it is now), for what I needed to happen I had to declare objects 11-20 unclickable in the Room_Load event.

I had forgotten about having to do this, or even why.

Problem solved, anyway. All I did was while the right mouse button was being held down, the objects would be clickable, and not when the button was released.

Works splendedly now, guys, thanks for putting up with my foolishness ;)
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

SMF spam blocked by CleanTalk