G
GunnyBoy
Guest
Most of the tutorials I've done involves creating a "door" object for the player to run into and have which room to change to as well as the x and y position to start the player in each of the door objects creation code. While this works I'm trying to think of a way to do this with JUST the door objects unique ID name that follows a naming convention of "current_room_to_next_room" where "current_room" and "next_room" change depending on the rooms I make. I was also going to try to figure out how to parse the unique ID names to automatically make the variables needed for this, but that's for later if this first idea works.
Anyway, from what I can find you can't make any sort of call to any object that isn't in the room you're current in, so what I'm currently trying to do is tell the player what it needs to look for on room change so it can reposition itself. The order I feel like it should work in is this:
1. Player collides with door
2. Door contains variables in creation code for which room to move to
3. Player builds string based on variables that are identical to unique ID of door to look for in next room
4. Player moves to next room with current position being the same as previous room
5. Player looks for instance of door matching unique ID build earlier
6. Player gets x and y of that door
7. Player moves to that x and y position (with coded adjustments so it's not colliding with door)
I know there's probably more issues that need to be solved with this like how the camera will most likely need to be reposition so it's not moving to the player from far away, but I can solve those later. My main issue right now is converting the string into the name of the object to look for. It appears to be converting it correctly when I try to debug it, but its returning as if it doesn't exist in the room after the transition.
Here's the code I have so far, let me know if I'm not showing enough. Also, sorry if my variable naming is confusing, some of it is still placeholder.
Door in room 1 (object name: o_transition, ID name: rm_1_to_rm_2)
Creation code:
Player (Persistent)
Collision with o_transition:
Step event:
So my main goal right now is for "_new_x" and "_new_y" to equal 0 and 128 (The door in room 2 position), but it's returning -1 for "_next_room_spawn_object" which I think it means it think it doesn't exist even after the room change and the object clearly does exist, also the "_new_x" and "_new_y" are giving me weird numbers that I can't exactly pin point where it's coming from. The "asset_get_index" is returning the name of the object when I debug so my thinking is I'm building the string correctly, but somewhere converting that string for the game to look for the real object with that name doesn't seem to work. Any thoughts?
Anyway, from what I can find you can't make any sort of call to any object that isn't in the room you're current in, so what I'm currently trying to do is tell the player what it needs to look for on room change so it can reposition itself. The order I feel like it should work in is this:
1. Player collides with door
2. Door contains variables in creation code for which room to move to
3. Player builds string based on variables that are identical to unique ID of door to look for in next room
4. Player moves to next room with current position being the same as previous room
5. Player looks for instance of door matching unique ID build earlier
6. Player gets x and y of that door
7. Player moves to that x and y position (with coded adjustments so it's not colliding with door)
I know there's probably more issues that need to be solved with this like how the camera will most likely need to be reposition so it's not moving to the player from far away, but I can solve those later. My main issue right now is converting the string into the name of the object to look for. It appears to be converting it correctly when I try to debug it, but its returning as if it doesn't exist in the room after the transition.
Here's the code I have so far, let me know if I'm not showing enough. Also, sorry if my variable naming is confusing, some of it is still placeholder.
Door in room 1 (object name: o_transition, ID name: rm_1_to_rm_2)
Creation code:
Code:
_current_room = room;
_target_room = rm_2;
_target_spawn = asset_get_index(string(_target_room) + "_to_" + string(_current_room));
Collision with o_transition:
Code:
room_goto(other._target_room);
Code:
_door = instance_place(x, y, o_transition);
if _door != noone {
_next_room_spawn = string(room_get_name(_door._target_room) + "_to_" + room_get_name(_door._current_room));
_next_room_spawn_object = asset_get_index(_next_room_spawn);
}
if (instance_exists(_next_room_spawn_object)) {
_new_x = _next_room_spawn_object.x;
_new_y = _next_room_spawn_object.y;
}
Last edited by a moderator: