Reputation: 153
I'm making an RPG in Game Maker Studio Pro 1.4.1772, and I have a guy that can run around a demo room, and movement and collisions are all groovy.
I just tried to make a door to move to a new room. I've followed this example exactly, and have some weird issues. I don't think the issue is with my code (it obviously works - it's identical to the tutorial) so the problem is something else.
When my player character runs over the obj_door on the map, nothing happens. I've put debug messages into the collision event, and nothing. Nada. I've put a debug message into the creation code of the door:
show_debug_message("I exist:" + string(self));
And the string that prints is:
I exist:-1
Which I find odd.
So I edited my movement code that checks for collisions with obj_solid, and added the door collision code there:
if (place_meeting (x, y, obj_door)){ ...
Now, when I run into the door on the map, I get an error:
FATAL ERROR in
action number 1
of Step Event0
for object obj_player:
Variable <unknown_object>.<unknown variable>(100022, -2147483648) not set before reading it.
at gml_Script_scr_player_move (line 75) - player_x = other.target_x;
So when the object create code runs, it gives the object an id of -1, though I guess it's still actually running the create code? No collision is detected through the build-in collision event, but when I force the game to check for a collision with this object (that I'm not really sure even exists), it throws an error. Why is this happening, and what else can I try in order to fix it?
Upvotes: 1
Views: 1302
Reputation: 1037
other is reserved for usage in either collision event or while cycle. You are missusing it in the step event (log you posted says that clearly)
Upvotes: 0
Reputation: 3192
self
is -1
- it's a special value. For instance ID, you might want id
.
It is hard to guess without seeing more code, but place_meeting
won't automatically store the colliding object in other
- you might want to use instance_place
like
var door = instance_place(x, y, obj_door);
if (door != noone) {
player_x = other.target_x; // assuming that door has a target_x variable
// ...
}
Upvotes: 2