#Follower just spawns when the player moves

11 messages · Page 1 of 1 (latest)

ripe stump
#

Why does, when I change the room, the follower just spawns when I'm starting to move? How can I do that he spawn immediately?

Step Event of Player

......
// Update recording!
if (x != xprevious or y != yprevious)
{

    for(var i = array_size-1; i > 0; i--)
    {
        pos_x[i] = pos_x[i-1];
        pos_y[i] = pos_y[i-1];
        
        // toRecordSprite[i] = toRecordSprite[i-1];
// toRecord_Xscale[i] = toRecord_Xscale[i-1];


    }
    pos_x[0] = x;
    pos_y[0] = y;
    // toRecordSprite[i] = BladeDown_spr;
// toRecord_Xscale[i] = image_xscale;

}

Create Event of Player

xspd = 0; // X direction Speed
yspd = 0; // Y direction speed
move_spd = 2; // Move speed - du hattest 100, aber ich denke das sollte 2 sein basierend auf dem Rest des Codes

// Array variable examples
sprite[RIGHT] = BladeRight_spr;
sprite[UP] = BladeUp_spr;
sprite[LEFT] = BladeLeft_spr;
sprite[DOWN] = BladeDown_spr;

sprite_idle[RIGHT] = BladeIdleRight_spr;
sprite_idle[UP] = BladeIdleUp_spr;
sprite_idle[LEFT] = BladeIdleLeft_spr;
sprite_idle[DOWN] = BladeIdleDown_spr;

face = DOWN;
array_size = 20; // The amount of positions to record

for(var i = array_size-1; i >= 0; i--)
{
pos_x[i] = x;
pos_y[i] = y;
// toRecordSprite[i] = BladeDown_spr;
// toRecord_Xscale[i] = image_xscale;
}

Room start Event of Player

// Alarm[0] Event
if (!instance_exists(Bananan_obj)) {
var follower_1;

// Positioning based on player's facing direction
if (face == UP) {
    follower_1 = instance_create_layer(x, y + 16, "Instances", Bananan_obj);
} else if (face == DOWN) {
    follower_1 = instance_create_layer(x, y - 16, "Instances", Bananan_obj);
} else if (face == LEFT) {
    follower_1 = instance_create_layer(x + 16, y, "Instances", Bananan_obj);
} else { // RIGHT
    follower_1 = instance_create_layer(x - 16, y, "Instances", Bananan_obj);
}

follower_1.record = 10;

}

karmic drum
#

Assuming your follower is Bananan_obj, and it looks like it is, and this is indeed the full room start room event of your player object, then the object should be created immediately -- provided that object doesn't exist already. There must be a different reason you cant see him immediately. Check to see if an instance of that object exists using the debugger prior to him becoming visible.

What is the alarm 0 event referenced in the comment?

// Alarm[0] Event
if (!instance_exists(Bananan_obj)) {
    var follower_1;

    // Positioning based on player's facing direction
    if (face == UP) {
        follower_1 = instance_create_layer(x, y + 16, "Instances", Bananan_obj);
    } else if (face == DOWN) {
        follower_1 = instance_create_layer(x, y - 16, "Instances", Bananan_obj);
    } else if (face == LEFT) {
        follower_1 = instance_create_layer(x + 16, y, "Instances", Bananan_obj);
    } else { // RIGHT
        follower_1 = instance_create_layer(x - 16, y, "Instances", Bananan_obj);
    }

    follower_1.record = 10;
}
ripe stump
#

Oh yeah, I delted that, there shouldn't be a Alarm[0] Event.

karmic drum
#

Alright, well, same deal. Check to see if the object instance exists using the debugger first.

#

If it exists, but you can't see him, you're gonna want to check the code of that object.

#

I'm assuming that the object is set up to go to the player's X and Y position several positions ago.

#

And it's likely that there isn't an X and Y position several positions ago because the player just appeared in the room. Or, if there is, they are X and Y coords from the previous room. So he's either going to some kind of default position, or to the player's X and Y from the last room prior to the room transition. Depends on how you set it up.

#

You can use the debugger to see whether the instance exists, and, if it does, what its x and y positions are within the room.

#
    if (face == UP) {
        follower_1 = instance_create_layer(x, y + 16, "Instances", Bananan_obj);
    } else if (face == DOWN) {
        follower_1 = instance_create_layer(x, y - 16, "Instances", Bananan_obj);
    } else if (face == LEFT) {
        follower_1 = instance_create_layer(x + 16, y, "Instances", Bananan_obj);
    } else { // RIGHT
        follower_1 = instance_create_layer(x - 16, y, "Instances", Bananan_obj);
    }

...This code here should create the object 16 pixels from the player, but it's only going to do that if the object doesn't exist already. And I don't know whether there might be another instance of Bananan_obj in the room already, or if he is persistent, etc.

ripe stump
#

Ok, thanks I did! I did the follower persistent and now it works! Thank you so much!

karmic drum
#

Uh. Alright. Please be sure to think through the consequences marking that object as persistent may have on any of your other code.