This should be very simple... but it's not...

jlshown

Member
Hello all!
if (instance_place(1401,131, Obj_BossBarrier) && score = 8)
{
instance_destroy( );
audio_play_sound(sfx_dooropen, 10, false);
}

This is my simple GML, but the BossBarrier will not destroy, even if I use the object name Obj_BossBarrier.
This is in the Obj_hammer with other collisions that are working fine.
A bit of advice please!
Thank you!
 

angelwire

Member
First off, what do the numbers "1401" and "131" represent? Are they the coordinates to an object or something?

Secondly, make sure the conditions are right to for the "if" statement. Put show_debug_message("If statement good"); inside the "if" statement curly brackets to see if there is an instance at the place and the score is in fact 8. (quick note, it's a good programming habit to use "score == 8" instead of just "score = 8" because "==" usually means "is it equal to" and "=" usually means "set it equal to")

If the "if" statement is working like you want it to, then you'll see "If statement good" show up in Gamemaker's output window. Let me know if you see it or not.

Also, you should put the name of the instance you want to destroy inside of instance_destroy() (unless you want to destroy the object that the code is in)

So your code should look like this:
GML:
if (instance_place(1401,131, Obj_BossBarrier) && score == 8)
{
show_debug_message("If statement good");
instance_destroy(Obj_BossBarrier);//Or whatever you want to destroy
audio_play_sound(sfx_dooropen, 10, false);
}
 

Roldy

Member
The first thing would be to verify your conditions are met. e.g. does the sound play? Put a show_debug_message inside the if block to verify it is being triggered.

Secondly if this is being run in an Obj_hammer instance then instance_destroy is being called in that context.

You may want to store the return value of instance_place and destroy the specific instance you are colliding with.

GML:
var _inst = instance_place(1401,131, Obj_BossBarrier);

if (_inst != noone && score == 8) {
    instance_destroy(_inst);
}
 

jlshown

Member
First off, what do the numbers "1401" and "131" represent? Are they the coordinates to an object or something?

Secondly, make sure the conditions are right to for the "if" statement. Put show_debug_message("If statement good"); inside the "if" statement curly brackets to see if there is an instance at the place and the score is in fact 8. (quick note, it's a good programming habit to use "score == 8" instead of just "score = 8" because "==" usually means "is it equal to" and "=" usually means "set it equal to")

If the "if" statement is working like you want it to, then you'll see "If statement good" show up in Gamemaker's output window. Let me know if you see it or not.

Also, you should put the name of the instance you want to destroy inside of instance_destroy() (unless you want to destroy the object that the code is in)

So your code should look like this:
GML:
if (instance_place(1401,131, Obj_BossBarrier) && score == 8)
{
show_debug_message("If statement good");
instance_destroy(Obj_BossBarrier);//Or whatever you want to destroy
audio_play_sound(sfx_dooropen, 10, false);
}

Hello Angelwire! Thank you. the 1401, 131 are the x, y of the collision, I'm going to try this now.
 

jlshown

Member
The first thing would be to verify your conditions are met. e.g. does the sound play? Put a show_debug_message inside the if block to verify it is being triggered.

Secondly if this is being run in an Obj_hammer instance then instance_destroy is being called in that context.

You may want to store the return value of instance_place and destroy the specific instance you are colliding with.

GML:
var _inst = instance_place(1401,131, Obj_BossBarrier);

if (_inst != noone && score == 8) {
    instance_destroy(_inst);
}
Thank you very much Roldy!
 

jlshown

Member
First off, what do the numbers "1401" and "131" represent? Are they the coordinates to an object or something?

Secondly, make sure the conditions are right to for the "if" statement. Put show_debug_message("If statement good"); inside the "if" statement curly brackets to see if there is an instance at the place and the score is in fact 8. (quick note, it's a good programming habit to use "score == 8" instead of just "score = 8" because "==" usually means "is it equal to" and "=" usually means "set it equal to")

If the "if" statement is working like you want it to, then you'll see "If statement good" show up in Gamemaker's output window. Let me know if you see it or not.

Also, you should put the name of the instance you want to destroy inside of instance_destroy() (unless you want to destroy the object that the code is in)

So your code should look like this:
GML:
if (instance_place(1401,131, Obj_BossBarrier) && score == 8)
{
show_debug_message("If statement good");
instance_destroy(Obj_BossBarrier);//Or whatever you want to destroy
audio_play_sound(sfx_dooropen, 10, false);
}
Hello Angelwire,
I used your code, but the debug message doesn't show up. So could it be not recognizing the score? The score is set up in dnd. Or perhaps the Boss_Barrier?

There are three levels. each level has a barrier door, that must have a collision that destroys the door if the score total is 8 for the room and then the sound effect for the door plays.

What do you need from me in terms of information?
Thank you,
Jeanette
 

Roldy

Member
Hello Angelwire,
I used your code, but the debug message doesn't show up. So could it be not recognizing the score? The score is set up in dnd. Or perhaps the Boss_Barrier?

There are three levels. each level has a barrier door, that must have a collision that destroys the door if the score total is 8 for the room and then the sound effect for the door plays.

What do you need from me in terms of information?
Thank you,
Jeanette
This is a good chance to use a debugger if you havn't already. But if you want to continue debugging with show_debug_message then I would suggest the following:

GML:
var _inst = instance_place(1401,131, Obj_BossBarrier);


show_debug_message("Collide: " + string (_inst != noone));

if (_inst != noone) {

    show_debug_message("Score: " + string (score));

    if (score == 8) {
        show_debug_message("Destroying Instance");
        instance_destroy(_inst);
    }
}
This will help let you see your values step by step.

On a side note: I know 'score' is built in variable for DnD. However, I don't know the scope of it. It might be global.
 
Last edited:

jlshown

Member
This is a good chance to use a debugger if you havn't already. But if you want to continue debugging with show_debug_message then I would suggest the following:

GML:
var _inst = instance_place(1401,131, Obj_BossBarrier);


show_debug_message("Collide: " + string (_inst != noone));

if (_inst != noone) {

    show_debug_message("Score: " + string (score));

    if (score == 8) {
        show_debug_message("Destroying Instance");
        instance_destroy(_inst);
    }
}
This will help let you see your values step by step.

On a side note: I now score is built in variable for DnD. However, I don't know the scope of it. It might be global.
Roldy! You Rock!
Here's what I ended up with:

X://windows/Runner.exe -game "Y:/Testing_Barrier_Sound_Game3_31703A95_VM\Testing Barrier Sound Game3.win"
Attempting to set gamepadcount to 12
DirectX11: Using hardware device
Collision Event time(microsecs)=3
Total memory used = 14371770(0x00db4bba) bytes
Entering main loop.
**********************************.
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Attempting to set gamepadcount to 0
Not shutting down steam as it is not initialised
Script_Free called

So does this mean it's not connecting to the score which is defined in the obj_level_controller using DnD and I'm not using a gamepad.

under create:
score = real(0);
Then in the draw event:

1605824742419.png



Thank you again!
 

Roldy

Member
Roldy! You Rock!
Here's what I ended up with:

X://windows/Runner.exe -game "Y:/Testing_Barrier_Sound_Game3_31703A95_VM\Testing Barrier Sound Game3.win"
Attempting to set gamepadcount to 12
DirectX11: Using hardware device
Collision Event time(microsecs)=3
Total memory used = 14371770(0x00db4bba) bytes
Entering main loop.
**********************************.
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Collide: 1
Score: 0
Attempting to set gamepadcount to 0
Not shutting down steam as it is not initialised
Script_Free called

So does this mean it's not connecting to the score which is defined in the obj_level_controller using DnD and I'm not using a gamepad.

under create:
score = real(0);
Then in the draw event:

View attachment 35780



Thank you again!

Well it definitely means your variable score is 0 when you collide.

I am not that familiar with DnD and its Score nodes. Sorry, I am not sure the scope of them or where you are setting the score via DnD.

But yes, the problem is the 'score' variable in that scope is never being incremented (always zero).

Most likely in your create event if you set score to 8 then your code would work. However, that isn't a solution. You need to access the same 'score' variable that is being set in DnD.
 

jlshown

Member
Well it definitely means your variable score is 0 when you collide.

I am not that familiar with DnD and its Score nodes. Sorry, I am not sure the scope of them or where you are setting the score via DnD.

But yes, the problem is the 'score' variable in that scope is never being incremented (always zero).

Most likely in your create event if you set score to 8 then your code would work. However, that isn't a solution. You need to access the same 'score' variable that is being set in DnD.
Roldy,
Thank you, at least I have something to go on!
Jeanette
 
Top