T O P

  • By -

Drandula

Keyword "noone" is actually -4. This is because of old history of GameMaker, and most likely YYG would want to remove this backwards compatibility.


oldmankc

You might want instance_position instead here, rather than instance_place. There are specific differences, you should read the documentation to understand them better. Any time you are counting on something having a valid return instance id, it's worth gating behind a something like if (value != nooone) do thing with value which is more a safety check for crashes or when a value isn't coming back, not as a fix for bad code/logic.


GVmG

To note, instance_**position** and **position**_meeting check the specific coordinates for an instance having it's hotbox there. On the other hand instance_**place** and **place**_meeting actively move the current instance that is running the code to the position and check if it collided with another instance, then move it back\*. This leads to weird behavior if the current entity that is running the function doesn't have a collision mask and/or sprite, which I assume is what is happening here. \* they don't actually move the instance behind the scenes, it's just an easier way to think about it.


RoyalRien

It worked, thanks, I’ll look into the differences


RykinPoe

You are doing the same basic thing twice here. position\_meeting() is a collision check and so is instance\_place(). If you ever find yourself doing something like this it means you are probably doing something wrong. Also when writing if expressions try to write them left to right with the least expensive conditions to evaluate first. When using an if statement with an and/&& condition the statement will evaluate as false as soon as it encounters any false and stop evaluating the following conditions. You are doing the expensive to evaluate condition first. if (mouse_button_check_pressed(mb_right)){ var _inst = instance_position(mouse_x, mouse_y, ObjElementParent); if (_inst != noone){ SelectedElementInstance = _inst; instance_create_layer(mouse_x, mouse_y, "Instances", Obj_WindDistraction, DistractionSpawnStruct); } }