• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Function instance_position not find object

G

grossik

Guest
Hello
I have script to find object by function instance_position, but the function doesn't find object.
So I create a new script that creates an object and then I want to find the object, but it still doesn't work.
Code:
Code:
var ss = instance_create(real((real(NPCSouradnice[0]))*32), real((real(NPCSouradnice[1])+1)*32), obj_dedula);
show_debug_message(ss.x);
show_debug_message(ss.y);
var inst = instance_position(real((real(NPCSouradnice[0]))*32), real((real(NPCSouradnice[1])+1)*32), obj_dedula);
show_debug_message(real(NPCSouradnice[0])*32);
show_debug_message((real(NPCSouradnice[1])+1)*32);
show_debug_message(inst);
if(inst != noone) {
    show_debug_message(NPCMessage[1]);
    inst.text = string(NPCMessage[1]);
}
Output:
576
288
576
288
-4
 
H

Homunculus

Guest
Badly written code aside (what do you need all those real() for?), one reason for a case like this not to work is because of the bounding box or collision mask. If you instance does not have a sprite, or the sprite has a collision mask that does not overlap its origin, this check will (currectly) fail.
 
G

grossik

Guest
Badly written code aside (what do you need all those real() for?), one reason for a case like this not to work is because of the bounding box or collision mask. If you instance does not have a sprite, or the sprite has a collision mask that does not overlap its origin, this check will (currectly) fail.
Thank you. My object have a manual mask and origin. Now it works
 
Top