Legacy GM How to get information from object if coordinates are known? And passing information to others?

Hi,

I need to get either the sprite name of an object which I know the coordinates of, or maybe get the value of a variable instead held within that object. Preferably both. How do I do this?

EDIT:

Instead of a new thread I'm editing this one as my query has changed slightly but is still related to the original post.

I need this code to work:

Code:
var objectName = object_get_name(object_index);

show_debug_message("Clicked: " + objectName);

object_above = instance_position(x, y-50, objectName);
object_right = instance_position(x+50, y, objectName);

show_debug_message("Above: " + string(object_get_name(object_above)));
show_debug_message("Right: " + string(object_get_name(object_right)));

if (place_meeting(x, y-50, objectName))
{  
    show_debug_message("found above");
    newMatches = matched + object_above.matched;
    matched = newMatches;
    object_above.matched = newMatches;
}

if (place_meeting(x+50, y, objectName))
{
    show_debug_message("found right");  
    newMatches = matched + object_right.matched;
    matched = newMatches;
    object_right.matched = newMatches;
}
Basically, I'm making a falling block game, and this code is what I'm trying to use as a "neighbour finder". It is in the parent object of the main game block. It should check the block above it and to the right of it if they are the same kind of block and if so add it's "matched" int with the neighbour and passing the new value to both objects. I've been at this for a couple of hours and I'm pretty tired so I dont know if I missed something or even am understandable.

Please help!
 
Last edited:
The thing is that I don't know exactly what object it is, it inherits all behaviour from a parent, but I need to know which sprite it uses to know how to handle it.

It is a falling block puzzle game, I've got this in the Left Button mouse click event (of the block): show_debug_message(sprite_get_name(sprite_index)); and it shows me the name of the sprite for the block I clicked.
I need to know how to get the sprite name of the next block, sort of a coords x+50 thing, preferably at the same time as clicking the first block. Example:

show_debug_message(sprite_get_name(sprite_index) + " " + the sprite name of the next block at x+50);
 
Last edited:

RangerX

Member
If you know the position of the instance, use "collision_point". This function returns the instance id. With the instance id you can go check inside what sprite index or object index it uses and then do your things accordingly.
 
You can pass the keyword 'all' instead of a specific object or instance and as you may guess from the name, it will check for all object types.
 

FrostyCat

Member
Repeat after me:

Objects don't exist in rooms, instances exist in rooms.

Your instance_position() is returning an instance ID, not an object ID. Don't use it with object_get_name(). Get object_index from it first.
Code:
instance_above = instance_position(x, y-50, objectName);
instance_right = instance_position(x+50, y, objectName);

if (instance_above != noone) {
  show_debug_message("Above: " + string(object_get_name(instance_above.object_index)));
}
if (instance_right != noone) {
  show_debug_message("Right: " + string(object_get_name(instance_right.object_index)));
}
Similarly you can also get sprite_index from the found instance (e.g. instance_right.sprite_index).

Note that I have changed your variable names so that you stop thinking you've found objects. Change the rest in your code.
 
Ok! I have clocked maybe 15h of Game Maker so I'm not really that savvy, thank you for the tip!

But how do I make my if(place_meeting) to work? I can visually see that they have a match either above or to the right but it does not register.
 

FrostyCat

Member
You don't need the place_meeting(), the values in instance_above and instance_right would have already told you whether the blocks were found. If you get noone then they're not found, otherwise something is there. The Manual entry on instance_position() tells you this.

And please, read this article before deciding that place_meeting() is right for you. instance_place() and place_meeting() do not check the same thing.
 
Top