Windows Simultaneous room and character swap

11oyd

Member
Hi, I'm working on a game where you can switch between one of four music genre themed characters but each time you swap characters, the characters swap to a room matched to that character's theme. This operation is working correctly the first time that I perform it but will not work subsequent times. All objects are persistent.

There four character transformations are each coded like this;

key_class = keyboard_check_pressed(ord("Z"))
key_funk = keyboard_check_pressed(ord("X"))
key_rock = keyboard_check_pressed(ord("C"))

if key_class {

instance_create_layer(x,y,0,oClassHero);
room_goto(ClassicalWorld);
show_debug_message("C");
instance_destroy();
}

if key_rock {
instance_create_layer(x,y,0,oRockHero);
room_goto(RockWorld);
show_debug_message("C");
instance_destroy();
}

if key_funk {
instance_create_layer(x,y,0,oFunkHero);
room_goto(FunkWorld);
show_debug_message("C");
instance_destroy();
}

Any help is greatly appreciated!
 

Roldy

Member
Hi, I'm working on a game where you can switch between one of four music genre themed characters but each time you swap characters, the characters swap to a room matched to that character's theme. This operation is working correctly the first time that I perform it but will not work subsequent times. All objects are persistent.

There four character transformations are each coded like this;

key_class = keyboard_check_pressed(ord("Z"))
key_funk = keyboard_check_pressed(ord("X"))
key_rock = keyboard_check_pressed(ord("C"))

if key_class {

instance_create_layer(x,y,0,oClassHero);
room_goto(ClassicalWorld);
show_debug_message("C");
instance_destroy();
}

if key_rock {
instance_create_layer(x,y,0,oRockHero);
room_goto(RockWorld);
show_debug_message("C");
instance_destroy();
}

if key_funk {
instance_create_layer(x,y,0,oFunkHero);
room_goto(FunkWorld);
show_debug_message("C");
instance_destroy();
}

Any help is greatly appreciated!
What instance/object is running this code? Some controller object? From the Hero instances?
 

11oyd

Member
There are four unique character objects that are coded this way. This particular example is ElectronicHero. Each hero uses the z,x and c keys to switch between the other characters.
 

Roldy

Member
There four character transformations are each coded like this;
This code is run in the Step event?

This operation is working correctly the first time that I perform it but will not work subsequent times.


What does 'will not work' mean? You press a key and nothing happens? The game crashes? You put a breakpoint in the code but no breakpoint is hit? You don't see the ' show_debug_message("C")' output when hitting the keys? You do see that but don't change rooms.... etc...
 

11oyd

Member
It will go to the room but the new character doesn't appear. If I remove the room_goto function, the characters all swap nicely.
 

Roldy

Member
It will go to the room but the new character doesn't appear. If I remove the room_goto function, the characters all swap nicely.

Does the 'new character' get created in the second room when you press a key? What does exist once the room is changed?

Put a breakpoint in the code for when you detect key press. step through and watch what happens, look at the number of instances that exist etc...

What happens when you press the key?

 

11oyd

Member
The new character will not come through to the next room in subsequent attempts. All that appears is the room that I select.

I can see the debug message appearing only the first time that I transform. Subsequent times it will say "Specified layer does not existC"

Debugger connected
13 code buffers added (6144)
Debug_SendGameStructure: packet size 76687
C
Specified layer does not existC

These are all in a step event, yeah.
 
Last edited:

Nidoking

Member
Well, do you want to create the instance on a particular layer, or do you want to create it at a particular depth? The "right" option is the one that matches what you want to do.
 

11oyd

Member
Well, do you want to create the instance on a particular layer, or do you want to create it at a particular depth? The "right" option is the one that matches what you want to do.
Thanks heaps! all I needed to do was use instance_create_depth.
 
Top