P
Pitu
Guest
Hey I'm having alot of problems with my code, so heres the scenario:
i have 2 sprites dedicated for 1 object and a player object.
Sprites:
1. spr_bed (image of empty bed)
2. spr_bed_used (image of bed with player's head to indicate he's sleeping in it)
Objects:
1. obj_player (player object)
2. obj_bed (object that uses spr_bed_used by default, and this object is plopped in the room from the start)
What I want to do:
I want it so that when I press E, the player should get out of bed and when he is out of bed and I press on it again, he should go back to bed.
How I'm trying to do it:
I'm basically creating and destroying the instances depending on which sprite_index it is currently on, here is the code to basically clear everything up. Help please it's not working! When I run the spr_bed_used appears but when i press E nothing happens!
obj_bed:
STEP EVENT:
i have 2 sprites dedicated for 1 object and a player object.
Sprites:
1. spr_bed (image of empty bed)
2. spr_bed_used (image of bed with player's head to indicate he's sleeping in it)
Objects:
1. obj_player (player object)
2. obj_bed (object that uses spr_bed_used by default, and this object is plopped in the room from the start)
What I want to do:
I want it so that when I press E, the player should get out of bed and when he is out of bed and I press on it again, he should go back to bed.
How I'm trying to do it:
I'm basically creating and destroying the instances depending on which sprite_index it is currently on, here is the code to basically clear everything up. Help please it's not working! When I run the spr_bed_used appears but when i press E nothing happens!
obj_bed:
STEP EVENT:
Code:
key_bed = keyboard_check_pressed(ord("E"));
if(sprite_index = spr_bed_used){
in_bed = true;
} else if(sprite_index = spr_bed){
in_bed = false;
}
//If in bed is true, destroy the player
if(in_bed = true){
with(obj_player){
instance_destroy();
}
}
//If in bed is false, create the player
if(in_bed = false){
instance_create(x, y-10, obj_player);
}
//If in bed is true, and you press E, in bed is false.
if(in_bed = true && key_bed){
in_bed = false;
}
//If in bed is false, and you press E, in bed is true.
if(in_bed = false && key_bed){
in_bed = true;
}