• 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] Continues Against NEXT Enemy Instead of PREVIOUS One

Velocity

Member
So, I'm working on a fighting game like Street Fighter II.

And I just made a continue room, which is a room where you can either continue fighting and try again, or quit to the main menu.

Like the examples in the video provided.


And I ALSO have an active array of enemies in my game, which I call an "Arcade Ladder".

And I ALSO created a system, where the game takes notice of the current battle room I'm in.

And so my continue is PUTTING me BACK into the ROOM I was in BEFOREHAND.

But I'm not FACING off against the same OPPONENT as before...



So if you lose a fight, an alarm goes off at the end.

Here's the code for it: (note. global.result 1 = Win, and global.result 2 = Draw)

if (global.result = 0)
{
room_goto_next();
}
else
if (global.result = 1)
{
room_goto(rm_continue);
}
else
if (global.result = 2)
{
room_goto(rm_continue);
}

And if you press Enter in the Continue Room, to CONTINUE, it goes to the PREVIOUS room.

Here's the code for if you press enter to continue:

room_goto(global.room_came_from);

In the Battle Room I have this in my Controller Create Event

global.room_came_from = room;

But, I've got an ARRAY, that controls WHICH opponents you face, in my own "Arcade Ladder"

This is in the Arcade Ladder Controller Create event

// Start of level (create)
if (room != rm_kemu)
{

instance_create(512,288, global.enemies[global.level]);
global.level++;

}

And this is in the Arcade Ladder Controller Game Start Event

// Start of game
global.enemies[0] = obj_itachiE;
global.enemies[1] = obj_nejiE;
global.enemies[2] = obj_narutoE ;
global.enemies[3] = obj_kakashiE
global.level = 0;

My PROBLEM is that when I CONTINUE in my Arcade Ladder - EVEN though I'm TRYING to face the same opponent AGAIN, before moving on to the NEXT one - it just cycles me through the NEXT opponent in the array, and continues doing so, opponent after opponent.

My question is, how can I make it so that when I continue - I face the SAME opponent I LOST to before moving on to the next room?

Sorry if this is a little complicated...
 
D

Destroy

Guest
instance_create(512,288, global.enemies[global.level]);
global.level++
This bit tells the ladder to summon the next enemy in the ladder every time the control object is created (Which I assume is every time the room is entered). Try removing global.level++ here and call this:

- When you want the following fight to have the next enemy
- However, just to be sure, before you move to the previous room again - this needs to be called at all costs before the arcane ladder object.

If you need more info just mention me! Also, just a friendly advice, be careful about copyright ;)
 

Velocity

Member
This bit tells the ladder to summon the next enemy in the ladder every time the control object is created (Which I assume is every time the room is entered). Try removing global.level++ here and call this:

- When you want the following fight to have the next enemy
- However, just to be sure, before you move to the previous room again - this needs to be called at all costs before the arcane ladder object.

If you need more info just mention me! Also, just a friendly advice, be careful about copyright ;)
I'm still trying to understand that...

Yeah, the Naruto characters are just place holders...

Any idea how I would go about coding that?
 
D

Destroy

Guest
I'm still trying to understand that...

Yeah, the Naruto characters are just place holders...

Any idea how I would go about coding that?
Well that largely depends on the details of your implementation. For example if there are two buttons in the continue room, REPEAT and NEXT: Then, if you chose REPEAT you'd just go to the previous room (now assuming that you had removed that piece of code as I said in the previous message). If you choose NEXT, you would use exactly the same code, except you'll put the global.level++ before it. If you for example used R to replay and N to next, it would look like this:

Code:
//R pressed event in the continue room
room_goto(global.room_came_from);


//N pressed event in the continue room
global.level++;
room_goto(global.room_came_from);
Replace the event with whatever suits you, or you can even use an if statement to perform the global.level++ line if the button is selected, if that is how your implementation works.

Again, if that does not work, I'd probably need to know more details, and if you do not understand something I'd need it a bit specifically.

-Des
 

Velocity

Member
Well, what I've done is I've got the succession of rooms (fighting arenas) all in a row.

And THEN when the character loses - they get taken to a room right at the bottom of my rooms list which is the Continue Room.

In THAT room - the ONLY thing I want the player to be able to do is REPLAY. There SHOULDN'T even BE a Next option - because I want the player to have to beat the CURRENT opponent first.

Can I do something like, in the Continue Room, global.level--, or global.level++ = false...

I dunno...

I just don't wanna mess up the array that worked so well before...
 
D

Destroy

Guest
Ah, I see! While being a somewhat inconvenient solution, global.level-- in the continue room would indeed work as it would cancel out the previously ran global.level++. However, what I would do is probably a dictionary, or if you want a simpler solution, a switch. Or even, an array of rooms. Or a 2D array. Okay I'll pick the probably simplest one, two arrays:

Code:
global.enemies[0] = obj_itachiE;
global.rooms[0] = rm_level1;
global.enemies[1] = obj_nejiE;
global.rooms[1] = rm_level2;
global.enemies[2] = obj_narutoE ;
global.rooms[2] = rm_level3;
global.enemies[3] = obj_kakashiE
global.rooms[3] = rm_level4;
That way you pair every room with its own enemy.
And then, replace your room create event with:

Code:
// Start of level (create)
if (room != rm_kemu)
{
    global.level = -1;
    for(int i = 0; i < array_length_1d(rooms); i++)
    {
        if(room == global.rooms[i])
        {
            global.level = i;
            break;
        }
    }
    instance_create(512,288, global.enemies[global.level]); //if global.level == -1, you are in a room where nothing is coded to spawn.
}
This code is somewhat hasty and made to be as understandable as possible and with as little modifications as possible. I think the very best thing you could do is naming your rooms conveniently - like, rm_fight00, rm_fight01, ... And then parsing last two chars of current room as a number. But to help you with that I'd need to know how you name your fighting rooms.
 

Velocity

Member
Code:
// Start of level (create)
if (room != rm_kemu)
{
    global.level = -1;
    for(int i = 0; i < array_length_1d(rooms); i++) //NOTE In THIS line it says assignment operator expected...
    {
        if(room == global.rooms[i])
        {
            global.level = i;
            break;
        }
    }
    instance_create(512,288, global.enemies[global.level]); //if global.level == -1, you are in a room where nothing is coded to spawn.
}
 

Velocity

Member
Sorry it's been a while

For THIS line of code:

for(int i = 0; i < array_length_1d(rooms); i++)

It's saying assignment operator expected...

I can't figure out what it needs instead...
 

Velocity

Member
I'm now getting THIS error when I test it:

Variable obj_arcade_ladder_controller.rooms(100137, -2147483648) not set before reading it.
at gml_Object_obj_arcade_ladder_controller_CreateEvent_1 (line 14) - for(var i = 0; i < array_length_1d(rooms); i++)
 
Top