GMS 2 Trio Partner System - Switching Positions w/ Arrays & Warping Rooms

Discussion in 'Programming' started by oturtmurr, Oct 11, 2019.

  1. oturtmurr

    oturtmurr Member

    Oct 10, 2019
    Hello GMC!

    I’m working on a project dealing with a partner following system with 3 objects. It has 1 leader, and 2 followers. These 3 individual objects are persistent, and are stored in arrays that allow me to change who’s who.

    In this system, they are able to switch roles, just like in the Mario & Luigi games. Once you press a button to switch, you are able to control the next character that has their own unique properties.

    In this system an array is created with 64 positions,
    //Create (for oParentPlayer)
    array_size = 64
    for (i = array_size - 1; i >= 0; i--) {
        _currentX[i] = x;
        _currentY[i] = y;
        _currentDir[i] = faceDir;
    It logs the new values of various variables, by shifting 1 down. This only happens when the player has moved. I remember to set the new current pos of the object in its Step event.
    /// Step (for oPlayer1)
    // If position is not the same as current, the player has moved.
    if (oPlayerA.x != _currentX[0]) || (oPlayerA.y != _currentY[0]) {
        hasMoved = 1;
    if (hasMoved) {
        for (var i = array_size-1; i > 0; i--) {
        _currentX[i]    = _currentX[i - 1];
        _currentY[i]    = _currentY[i - 1];
        _currentDir[i] = _currentDir[i - 1];
    /* New current position of character */
    _currentX[0]   = oPlayerA.x;
    _currentY[0]   = oPlayerA.y;
    _currentDir[0] = faceDir;

    Now, in the oParentPlayer object. I have a Step event, that runs the logic for following the leader. I use a switch statement and Enums to take care of different combinations and character placements. Depending on the combination, I set whether that object it is the leader or not, as well as it being a follower.

    If a follower has no control, meaning he has no control over the party, they will be set as a follower, after this, their X and Y variables will be set to an array that follows the position of the leader, but buffers, so it isn’t exact. This takes the name of the variable “record”.

    This allows me to distance the followers.
    if (oPlayerB.hasControl != true) && (oPlayerC.hasControl != true) {
       global.trioFollower[0] = oPlayerB;
       global.trioFollower[1] = oPlayerC;
       with (oPlayerB) {
           record = 15;
           oPlayerB.x = global.trioLeader._currentX[record];
           oPlayerB.y = global.trioLeader._currentY[record]; 
       with (oPlayerC) {
           record_2 = 25;
           oPlayerC.x = global.trioLeader._currentX[record_2];
           oPlayerC.y = global.trioLeader._currentY[record_2]; 
    If the combination is changed. I place the objects in the variables according to their combination. A-BC, B-AC, C-BA, etc.

    My 1st problem deals with the system and its flexibility to allow me to switch the current position of the leader, with the current position of the follower, so it isn’t an abrupt change when picking the next character.
    (Currently, the way I'm placing these characters is by fiddling with how far they are from the leader by lowering and raising the value of “record”). What I would like to do instead, is have PlayerB taking the position of PlayerA, and Player A taking PlayerB’s position.

    My 2nd problem, is having all 3 objects appear at a marker when transitioning to the next room. Since these 3 are persistent, they’ll keep the position of where they’re at when going to the next room, except for the leader, the followers will stay in their position regardless of a marker telling them to appear at X, Y.

    I have this system set up where once you collide with DoorA, it creates a fade in and fade out object, and puts you into the next room. oGameControl controls the logic of Room Start event where it places the oParParent object at the markers position.

    /// Room Start (oGameControl)
     if (global.entrance >= 1) {
        if (global.entrance == 1) {
            oParPlayer.x = oMarkerA.x;
            oParPlayer.y = oMarkerA.y;
    I can’t get the two follower objects to be placed at this position. When they are persistent this is impossible, but when they are not, it allows it to occur-except many other problems such as a non-existent object error arises when going to the next room.

    I’m wondering what I can do here. Move to DS Lists? I’ve looked around and seen that they are used widely. May you guys help, do you have any thoughts on what I could do?

    Last edited: Oct 11, 2019
  2. oturtmurr

    oturtmurr Member

    Oct 10, 2019
  3. Yal

    Yal GMC Memer GMC Elder

    Jun 20, 2016
    For problem 1, you could give the followers a "state" variable, which takes different values for "follow player normally", and "switch places with the player". In the switch-places state, you move the follower to where the player was, and move the player to where the follower was (using positions you stored in some variables before changing state). When they've reached the new places, switch back to the normal following state.

    For problem 2: in the Room Start event of the followers (which is run every time you enter a room, even with persistency), have them move to the player's position. You want to fill the stored-position array with the player's current position as well.
  4. oturtmurr

    oturtmurr Member

    Oct 10, 2019
    Thanks for the response! Right now, I'm attempting to fix the warp room situation, and I found that if I don't disable the follower logic code; they'll ignore the position set change I have for Room Start event.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice