reference object_get_name

G

Gridma

Guest
i need help

Code:
var targetBlock = position_meeting(block.x+16, block.y, object_get_name(block.object_index));
this code doesn't seem work, i want to check the block beside another are the same or not, how do i do it?

thanks
 
Dunno if this is completely right, but I wouldn't use the object_get_name function.

If I were to do it, it'd be something like:

Code:
var targetBlock = instance_position(block.x+1,block.y,block);

if (targetBlock == block) {
    // code to run if the block is the same
}
Of course, this code only checks to the right, you might wanna do a similar check with block.x-1 if you want to check to the left as well. Btw, haven't tested that code, it might need tweaking to do exactly what you want.
 
Last edited:

Mazey

Member
This worked for me:
Code:
var isSame = place_meeting(x+sprite_width,y,object_index);
You should only use sprite_width/sprite_height if the sprites are centered (they should be IMO, makes coding easier)
 

Weird Dragon

Wizard
GMC Elder
@Gridma , just a note regarding the object_get_name(obj) function if you ever want to use it in some other situation. That function returns the name as a string, which means that you can not apply it in a situation where you need an index number. But you can get the index number from the string with the function asset_get_index(name).
 

FrostyCat

Redemption Seeker
@Gridma:

You also need to stop using object.variable when there are multiple instances of the object in the room. If you want an object's instances to refer to their own instance variables, use just the variable identifier and be done with it. Don't use block.x+16, use x+16.

Alongside treating resource IDs and variable identifiers as strings, this is one of the worst and most common bad GMS rookie habits.
 
Top