Jump to content


Photo

Switching Between Characters


  • This topic is locked This topic is locked
1 reply to this topic

#1 IndieNoob

IndieNoob

    GMC Member

  • New Member
  • 25 posts

Posted 12 July 2011 - 02:45 PM

I have game where you control three characters separately.

//Controller Step Event
//Switch between playable characters
if(keboard_check_pressed(ord("X"))){
    global.switch_chars+=1;
    if(global.switch_chars>3){
        global.switch_chars=1;
    }
}


Then in each of the character step events I have an if statement checking to see if they are the character that is currently being controlled.

Here's my problem. When the three characters stack on one another, I want to destroy the three and create a fourth character in their place (its a fusion of the three).

//Also in the Controller Step Event

//Fuse
if(global.stack==0)&&(global.stack2==0){
    if(keyboard_check_pressed(vk_down))&&(global.fuse==0){
        instance_create(oPlayer3.x,oPlayer3.y,oFusionPlayer); //The fusion player is as tall as the stack, so it is create with the coordinates of the top character
        with(oPlayer1){
            instance_destroy();
        }      
        with(oPlayer2){
            instance_destroy();
        } 
        with(oPlayer2){
            instance_destroy();
        }   
        global.fuse=1;
}


//Un-Fuse? Haha
if(keyboard_check_pressed(vk_down))&&(global.fuse==1){
    instance_create(x+32,y+32,oPlayer1);
    instance_create(x+16,y+16,oPlayer2);
    instance_create(x,y,oPlayer3);
    with(oFusionPlayer){
        instance_destroy();
    }
    global.fuse=0;
}


Ok, so the issue is that the code doesn't always work. It's inconsistent.
The inconsistent parts are the global variables stack and stack2.

//Player1 Step Event
if(place_meeting(x,y-1,oPlayer2)){
    global.stack=0;
}else{
    global.stack=1;
}

The same code is in the second player's step. It checks to see if the third character is on top of it.
If I start the game, stack the players and keep tapping the down key, they will swap between the three and the fusion.
Then, if I move them away from each other, then stack them back up, the variables don't change back to indicate that they are stacked.

I'm not sure why. I used the debug window and there is only one instance of each object.
I thought that maybe it was looking for collision with an object that wasn't destroyed properly, but I'm not sure now.

Does anyone have any ideas? Or perhaps a better way to set this up? I'm pretty frustrated. Haha

Edited by IndieNoob, 12 July 2011 - 02:57 PM.

  • 0

#2 IndieNoob

IndieNoob

    GMC Member

  • New Member
  • 25 posts

Posted 12 July 2011 - 03:10 PM

SOLVED.

Like I expected, GM was having a problem with

if(place_meeting(x,y-1, oPlayer))

I think it was looking for a specific instance?

Not sure why it fixed the problem, but everything works now that I changed it to:

if(instance_position(x,y-16,oPlayer))...
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users