Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Sektor 13 on Thu 18/08/2005 12:14:57

Title: Object.GetAtScreenXY not working (SOLVED)
Post by: Sektor 13 on Thu 18/08/2005 12:14:57
I am trying to use GetObjectAt(x,y)... But it just doesn't work, i tried with object based (2.7) command too.
Like this:

if (GetObjectAt(93,37)==1) cJack.Say("blabla");

or.

if (Object.GetAtScreenXY(93,37) == oPIC1) cJack.Say("xdalkhjd");

I puted the code on the hotspot -> interaction click code (so if you click on hotspot and object is in those coordinates Jack should say the lines..) but it doesn't.

I even tried to put the code to "Enter room for the first time" script, but it still doesn't work.

Object is set on those coordinates, i checked in the editor, and later even used move command for object to 93,37 co. but it still doesn't work.

Using ags 2.7...
Title: Re: Get Object At BUG/ ERROR?
Post by: Sektor 13 on Thu 18/08/2005 16:27:06
Now i used  o"objectname".x == 93 and  o"objectname".y == 37 and it works fine .

And another questing, how can you define multiple objects in one line ?

like: 0bject[from 3 to 7].X ==93.... ???

so that the code would look if object 3,4,5,6,7 are on x==93 .
Title: Re: Get Object At BUG/ ERROR?
Post by: Rui 'Trovatore' Pires on Thu 18/08/2005 19:17:10
Use a "while" statement.

int counter=0;
while (counter<=7) {
   object[counter].DoWhatever();
   counter++;
}
Title: Re: Get Object At BUG/ ERROR?
Post by: Sektor 13 on Thu 18/08/2005 20:29:32
Thanks Brisby..
I hoped there is simpler solution, like if you are using old scripting you can write (GetObjectAt(x,y)>=0) and it gets all object, with no extra writing..

So any idea why  GetObjectAt(x,y) doesn't work (first post )..?
Title: Re: Get Object At BUG/ ERROR?
Post by: strazer on Sun 21/08/2005 00:27:42
Is the object transparent at its bottom-left corner?
I think if "Pixel-perfect click detection" is enabled in the General settings, only opaque parts of the object graphic return the object.
Title: Re: Get Object At BUG/ ERROR?
Post by: Sektor 13 on Sun 21/08/2005 16:18:24
Object it full square (has no transparent areas). I don't know why object.X== and object.Y == ; works fine than ? What is the different between if (GetObjectAt(93,37)==1) cJack.Say("blabla"); and object.x== .... than ?
Title: Re: Get Object At BUG/ ERROR?
Post by: Khris on Sun 21/08/2005 17:22:52
Try using

Display("%d", GetLocationType(93, 37)); or Display("%d", GetObjectAt(93, 37));

Maybe it'll help.
(And keep in mind that GetObjectAt() uses screen-coordinates.)
Title: Re: Get Object At BUG/ ERROR?
Post by: Sektor 13 on Sun 21/08/2005 17:35:28
Actually i wanted to get object position to move some puzzle piece around, and they get blocked if object is detected nearby,  my room is not scrollable.  I made it work with object.X==. and object.Y==, but i still wonder why GetObjectAt doesn't work..
Title: Re: Get Object At BUG/ ERROR?
Post by: monkey0506 on Mon 22/08/2005 01:31:52
Have you tested to see that the object being returned is the same as oPIC1?  It would appear that it's not, but you could test it with something like:

Object* objat = Object.GetAtScreenXY(93, 37);
string objatstr;
string pic1str;
if (objat != null) objat.GetName(objatstr);
else StrCopy(objatstr, "NULL");
oPIC1.GetName(pic1str);
if (!StrComp(pic1str, "")) StrCopy(pic1str, "NULL");
Display("Object.GetAtScreenXY(93, 37) = %s.  oPIC1 = %s.", objatstr, pic1str);


Which will display the name of the object the mouse is over and the name of oPIC1 (displaying "NULL" if they are left blank).  I hope you get the problem resolved.
Title: Re: Get Object At BUG/ ERROR?
Post by: Pumaman on Tue 23/08/2005 18:51:01
Quote from: Sektor 13 on Sun 21/08/2005 17:35:28
I made it work with object.X==. and object.Y==, but i still wonder why GetObjectAt doesn't work..

The object.X and object.Y are the co-ordinates of the bottom-left corner of the object.

GetObjectAt checks whether there is a non-transparent pixel belonging to the object at those co-ordinates.

They are totally different checks, which is why they can return different results.
Title: Re: Get Object At BUG/ ERROR?
Post by: Sektor 13 on Wed 24/08/2005 16:50:34
still, my object is not transparent, but i used objects bottom-left coordinates as X an Y...
Title: Re: Get Object At BUG/ ERROR?
Post by: Gilbert on Thu 25/08/2005 02:16:23
Did you mean, the bottom left pixel of your object is not transparent?
Title: Re: Get Object At BUG/ ERROR?
Post by: monkey0506 on Thu 25/08/2005 04:12:25
I think he's saying none of it is transparent.  Or at least not the pixel at (93, 37).  Which would explain the confusion as to the results...
Title: Re: Get Object At BUG/ ERROR?
Post by: Khris on Thu 25/08/2005 10:23:33
Quote from: Sektor 13 on Sun 21/08/2005 16:18:24
Object it full square (has no transparent areas).
Title: Re: Get Object At BUG/ ERROR?
Post by: Gilbert on Thu 25/08/2005 10:34:08
Try to check for (93, 36) and see if it works, maybe sometimes the object pivot was set a line lower than the actual displayed sprite (I'm not quite sure about it though).
Title: Re: Get Object At BUG/ ERROR?
Post by: Sektor 13 on Thu 25/08/2005 18:01:31
ok, i have done some testing.

I tried coordinates in the middle of my object and it works !
So I went further.
--------------------
**edited** i deleted some of the text, as it was wrong**
--deleted text--
**end of edit**
---------------------
I used Object.GetObjectAtXY(...)==object)... on all far points of my object. And i found out that GetObjectAtXY detects my object at MAX X = from 75 to 83  AND  Y from 28 to 36 This means that  GetObjectATXY has offset for Y -1 and it is correct for X.

???
Title: Re: Get Object At BUG/ ERROR?
Post by: Kweepa on Thu 25/08/2005 21:09:57
AGS probably takes your Y position, subtracts the sprite height, and draws the sprite.
So for your example:

y = 37
h = 9
Draw at y-h = 37-9 = 28

Then it fills pixel rows 28-36.

Confusing, but predictable.
Might be dangerous to fix.
Probably needs a note in the manual.
Title: Re: Get Object At BUG/ ERROR?
Post by: Pumaman on Fri 26/08/2005 18:37:54
Got it in one, Steve.

Yes, this is slightly confusing but I daren't fix it because there are too many games relying on the current system for lining up graphics and so on.

I'll add a note to the manual to make sure people are aware of it.

Edit by strazer:

Beta 5 has a note for the Object.Y property.

--

(Irrelevant messages removed to unbump thread.)