• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED First time making a game, character won't warp to the start of new level?

T

Tori

Guest
I am making a very simple Platformer to try and learn the basics of the program. I am having a problem with my warping as instead of warping to the start of a new room, my player will warp to the end of the room, making the level basically pointless. Any suggestions on how to fix it? I've tried some youtube tutorials and i'm still unsure what I've done wrong. Seems like it could be a pretty basic mistake though. If any part of this post is against the rules please let me know, it's my first time using the forums too.
 

fishfern

Member
Hi there, welcome to the forums!

Hmm, it sounds like there could be some confusion in you warp code maybe? If possible, could you include a snippet of code from the code that 'warps' your player object?
 
T

Tori

Guest
Hi there, welcome to the forums!

Hmm, it sounds like there could be some confusion in you warp code maybe? If possible, could you include a snippet of code from the code that 'warps' your player object?
Hi, I'm still not sure what the right way to post code in this forum is, but here it is:

oPlayer Step Event
GML:
//Objects
var inst = instance_place(x,y,oWarp) ;
if (inst != noone) {
    with(oGame) {
        if(!doTransition) {
        spawnRoom = inst.targetRoom;
        spawnX = inst.targetX;
        spawnY = inst.targetY;
        doTransition = true;
        }
        }
}
oWarp Create Event
Code:
targetRoom = -1;
targetX = 0;
targetY = 0;
oGame Create Event (this was mostly to get a black screen effect when switching rooms but I'll put it here just in case)
Code:
guiWidth = display_get_gui_width();
guiHeight = display_get_gui_height();

blackAlpha = 0;

spawnRoom = -1;
spawnX = 0;
spawnY = 0;
doTransition = false;
oGame Draw GUI Event
Code:
if(doTransition){
    //Handle Black Fade Transition
    if(room != spawnRoom) {
        blackAlpha += 0.1;
        if(blackAlpha >= 1) {room_goto(spawnRoom)}
    } else {
        blackAlpha -= 0.1;
        if(blackAlpha <= 0) { doTransition = false; }
    }
    
    //Draw Black Fade
    draw_set_alpha(blackAlpha);
    draw_rectangle_color(0,0, guiWidth, guiHeight, c_black, c_black, c_black, c_black, false);
    draw_set_alpha(1);
}
oGame Room Start Event
Code:
if(spawnRoom == -1) exit;
oPlayer.x = spawnX;
oPlayer.y = spawnY;
And for the object Instances for oWarp in my first room rLevelOne

In rLevelOne
Code:
targetRoom = rLevelTwo
targetX = 39;
targetY = 144;
In rLevelTwo
targetRoom = rLevelThree
targetX = 66;
targetY = 282;

And rLevelThree
targetRoom = rMenu




Sorry if it's a pain going through all that, i've never done this before so i'm not sure where specifically the problem could be
 

Nidoking

Member
Is the oGame persistent? You seem to set its doTransition to true and then never back to false, unless you're creating a new one in each room.
 
T

Tori

Guest
Is the oGame persistent? You seem to set its doTransition to true and then never back to false, unless you're creating a new one in each room.
Hi, sorry about the late reply.
I'm not creating a new one in each room so maybe that has something to do with it.
I am not very experienced in coding so how would changing it back to false affect where the player ends up in the next room? And how would I code that? Thanks for the help either way, I'll try and mess around until it works but again, I have no idea how a majority of this stuff works.
 

Nidoking

Member
how would changing it back to false affect where the player ends up in the next room?
if(!doTransition)
{
spawnRoom = inst.targetRoom;
spawnX = inst.targetX;
spawnY = inst.targetY;
doTransition = true;
}
How would spawnX and spawnY get set if doTransition is true?

And how would I code that?
doTransition = false;

Setting variables is a very basic thing that you need to know how to do.
 
T

Tori

Guest
How would spawnX and spawnY get set if doTransition is true?



doTransition = false;

Setting variables is a very basic thing that you need to know how to do.
I'm pretty sure I understand how to set doTransition = false;, but if I were to just place it in the middle of the step event with no other explanation it would prevent my player character from actually warping. I am just unsure on what specific instructions are required to set doTransition to false so that it doesn't effect the warping, yet actually does something. I've messed around a bit and so far any coding where i've tried to make doTransition = false; has either messed up my warping code, given me an error, or done absolutely nothing.
If I misunderstood anything please correct me but this is my first time ever making a game and I've never used code before in my life, so I understand i may be a little slow with this kind of thing.
 

Nidoking

Member
Hang on, I do see a doTransition = false buried in your Draw GUI event. That should be fine, ultimately, although I'd be careful about setting your alpha value to a negative number. Are you sure the spawnX and spawnY coordinates are set correctly? As in, you're supposed to set them to the coordinates for the room you're warping to.
 
T

Tori

Guest
Hang on, I do see a doTransition = false buried in your Draw GUI event. That should be fine, ultimately, although I'd be careful about setting your alpha value to a negative number. Are you sure the spawnX and spawnY coordinates are set correctly? As in, you're supposed to set them to the coordinates for the room you're warping to.
I have added in the warp objects creation code in my first level
GML:
targetRoom = rLevelTwo
targetX = 39;
targetY = 144;
In my step event in oPlayer for oWarp, I have let spawnX and spawnY = inst.targetX and inst.targetY. That should let the spawn coordinates of spawnX and spawnY equal the targetX and targetY coordinates wouldn't it? I may be mistaken but that's how interpreted that.
 
T

Tori

Guest
Ok I think I could get it to work if I destroy the oPlayer object of rLevelOne and placing a new player object in the second room at the start of the room, I just need to figure out how to destroy the object once it warps. I'll update if this works.
 
T

Tori

Guest
Ok I think I could get it to work if I destroy the oPlayer object of rLevelOne and placing a new player object in the second room at the start of the room, I just need to figure out how to destroy the object once it warps. I'll update if this works.
Ok good news, I fixed two issues at once with this method!
I added the code
GML:
instance_destroy(oPlayer);
into my oPlayer Step event //Objects. This fixed both my warping issue and an issue i was having where my player object wasn't appearing when replaying the game from my game over and menu screen. I'll add my full line of code from my step event here:
Code:
//Objects
var inst = instance_place(x,y,oWarp) ;
if (inst != noone) {
    with(oGame) {
        if(!doTransition) {
        spawnRoom = inst.targetRoom;
        spawnX = inst.targetX;
        spawnY = inst.targetY;
        doTransition = true;
        instance_destroy(oPlayer);
        }
        }
}
To do this i just had to make sure the player object was put into every level/room.
 

Nidoking

Member
Ah, so the ROOMS were persistent. That's a completely different thing, and would have explained everything right at the beginning. The oPlayer wasn't "warping to the end". It was at the end because that's where you left it when you changed rooms.
 
T

Tori

Guest
Ah, so the ROOMS were persistent. That's a completely different thing, and would have explained everything right at the beginning. The oPlayer wasn't "warping to the end". It was at the end because that's where you left it when you changed rooms.
Ah, yeah that makes much more sense! Thanks for pointing it out.
 
Top