Legacy GM Errors with instance_place and is_undefined

D

Dracodino300

Guest
I am currently getting errors stating that "target.type not set before reading" inside an is_undefined statement, and instance stored under target should not have even been read.

The relevant code used is this:

Code:
target = check_hit_instance(x,y);
    if(target != noone && !is_undefined(target.type)){
    ...
with
Code:
///check_hit_instance(x,y);
var x1 = argument0;
var y1 = argument1;

if(!place_empty(x1,y1)){
    return instance_place(x1,y1,all);
}
else return noone;
Where the error occurs, the instance that is returned by check_hit_instance has no collision mask and no type variable, so as far as I can see it should never have been picked up by instance_place and also should just return false for is_undefined.

EDIT: problem with is_undefined solved, still have instance_place error
 
Last edited by a moderator:

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
is_undefined(value) is same as (value == undefined), it will not check for variables not being set. You'd want variable_instance_exists for that.

However, what you should want much more is checking for a specific object type/parent rather than checking for every single object and then checking if it happens to have that one variable.
 
D

Dracodino300

Guest
is_undefined(value) is same as (value == undefined), it will not check for variables not being set. You'd want variable_instance_exists for that.
I'd found variable_instance_exists, but there doesn't seem to be an alternative for GM:S 1.4.

However, what you should want much more is checking for a specific object type/parent rather than checking for every single object and then checking if it happens to have that one variable.
The reason I had the script like that was because all I need is the instance id for the colliding object, and grouping 90% of the objects I'm using under a single parent seems a bit redundant. Am I thinking about that wrongly?
 
D

Dracodino300

Guest
variable_instance_exists() has been reintroduced into GMS 1.4 for quite a while now.
Ah, thanks for that. My auto-complete doesn't seem to recognise it so I assumed it hadn't been implemented.

So I guess that's one problem solved. Any ideas about the instance_place issue?
 

FrostyCat

Redemption Seeker
Ah, thanks for that. My auto-complete doesn't seem to recognise it so I assumed it hadn't been implemented.

So I guess that's one problem solved. Any ideas about the instance_place issue?
My guess is that you have accidentally set a sprite to it, or its mask_index has become set. If you use all often, mistakes like this are easy to come by.
 
D

Dracodino300

Guest
My guess is that you have accidentally set a sprite to it, or its mask_index has become set. If you use all often, mistakes like this are easy to come by.
Fairly sure I haven't: I've tried making the bounding box empty, and setting mask_index to that of an empty sprite. Both attempts result in the same error.
 

FrostyCat

Redemption Seeker
Have you tried setting both sprite_index and mask_index to -1? Maybe what you think is an empty sprite is still counting for something.
 

TheouAegis

Member
As far as I know, a sprite with no bounding boxes defined still has a bounding box of one pixel. As Frosty said, only when sprite_index and mask_index are both -1 should collisions be non-existent.
 
Top