Legacy GM ISSUE WITH DESTROYING OBJECT IN NEXT ROOM.

EZTALES

Member
hey yall.
just having a small issue with destroying an object in the next room, im using a level system so when you reach a certain level, some things are deleted. heres the code. and yes the room uses physics.
/// room end
with (obj_player_stats) {
if level = 2
{ audio_stop_sound(sad_snowfall)
audio_play_sound(snd_snowfall_sadder,1,true)
instance_destroy(obj_textbox_18)
instance_destroy(obj_human_4)
}}

with (obj_player_stats) {
if level = 1
{ audio_stop_sound(snd_snowfall_sadder)
audio_play_sound(sad_snowfall,1,true)
}}
any help would be fantastic :}
 

samspade

Member
I'm not sure I fully understand what you're trying for. You're saying that you have Room A and Room B. If the player is in Room A and reaches a certain level you want objects in Room B to be destroyed?

You can't use instance_destroy on an object because instance destroy destroys an instance of an object and there is no instance of the object because that instance hasn't been created. Putting an object in a room in the editor basically just tells the game to create an instance of that object when that room is created. It doesn't exist before that so it can't be destroyed. There are lots of solutions to this apparent problem, while not most flexible, is probably this:

Code:
///create event of instance you want to destroy
with (obj_player_stats) {
    if (level > 1) {
        instance_destroy(other);
    }
}
The downside to this version is that the instance is created and then destroyed. This may have effects you don't want (e.g. in the destroy event it increases the player's score or something). An alternative way would be to have an object spawn in instances in the room rather than placing them there in the editor. For example:

Code:
///probably a create event or script called in a create event at room start
var level = obj_player_stats.level; //this assumes you will ever only have one and only one obj_player_stats

switch (level) {
    case 1:
        //spawn in some things
        break;
    case 2:
        //spawn in different things
        break;
}
Also as a note, your code is a little hard to read. Using code brackets and indentation would help.
 

EZTALES

Member
I'm not sure I fully understand what you're trying for. You're saying that you have Room A and Room B. If the player is in Room A and reaches a certain level you want objects in Room B to be destroyed?

You can't use instance_destroy on an object because instance destroy destroys an instance of an object and there is no instance of the object because that instance hasn't been created. Putting an object in a room in the editor basically just tells the game to create an instance of that object when that room is created. It doesn't exist before that so it can't be destroyed. There are lots of solutions to this apparent problem, while not most flexible, is probably this:

Code:
///create event of instance you want to destroy
with (obj_player_stats) {
    if (level > 1) {
        instance_destroy(other);
    }
}
The downside to this version is that the instance is created and then destroyed. This may have effects you don't want (e.g. in the destroy event it increases the player's score or something). An alternative way would be to have an object spawn in instances in the room rather than placing them there in the editor. For example:

Code:
///probably a create event or script called in a create event at room start
var level = obj_player_stats.level; //this assumes you will ever only have one and only one obj_player_stats

switch (level) {
    case 1:
        //spawn in some things
        break;
    case 2:
        //spawn in different things
        break;
}
Also as a note, your code is a little hard to read. Using code brackets and indentation would help.
:)
 
Top