• 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!

please help

reipor

Member
well, I was trying to make a system that when you're colliding with the obj_mosca{
eat = true
}

,and when it's not{
eat = false
}

and when eat = true and the keyboard_check (vk_space) {
instance_destroy ();
}

but even if the player is not colliding, when pressing space the obj_mosca is destroyed, I don't know how to fix it, I need help

I also can't finish this code, what I mean by it is: if eat = false && keyboard_check (vk_space)
{

}

nothing happens, using this code i hoped nothing would happen if eat = false, and i believe this is the problem. plz help me




My code:
 

Nidoking

Member
You know, there are CODE blocks on the forum that are perfectly fine for pasting code.

GML:
if (obj_player) place_meeting(x,y,obj_mosca){
     eat = true   
 
    if !place_meeting{
         eat = false
    }
}
Two things:
1. if (obj_player) is probably going to be true if there's an obj_player. Given that this is in obj_player, I suspect it's always true. So it conditionally does place_meeting and throws away the result.
2. Now it unconditionally (because you've already done something with the if) sets eat to true and, if there is no function called place_meeting, would set eat to false. Had you written the if conditions correctly, this means that it would only set eat to false if obj_player is both meeting AND not meeting an obj_mosca. That's impossible.
 

reipor

Member
You know, there are CODE blocks on the forum that are perfectly fine for pasting code.

GML:
if (obj_player) place_meeting(x,y,obj_mosca){
     eat = true  

    if !place_meeting{
         eat = false
    }
}
Two things:
1. if (obj_player) is probably going to be true if there's an obj_player. Given that this is in obj_player, I suspect it's always true. So it conditionally does place_meeting and throws away the result.
2. Now it unconditionally (because you've already done something with the if) sets eat to true and, if there is no function called place_meeting, would set eat to false. Had you written the if conditions correctly, this means that it would only set eat to false if obj_player is both meeting AND not meeting an obj_mosca. That's impossible.
thank you, but i still dont know what i need to do to fix that
 

TsukaYuriko

☄️
Forum Staff
Moderator
GML:
if (obj_player) place_meeting(x,y,obj_mosca){
    eat = true
 
    if !place_meeting{
        eat = false
    }
}
None of this does what you think it does.

I'll write out your code the way the compiler reads it.
GML:
if (obj_player >= 1)
{
    place_meeting(x,y,obj_mosca);
}

eat = true;

if (place_meeting < 1)
{
    eat = false;
}
I'm sure we can all agree that this is not what you meant by any stretch of the imagination... :)

Because your if condition is merely obj_player, the ID of obj_player will be evaluated.
If its ID is 0, the next line will not run.
If its ID is anything other than 0, the next line will run.
This is because any value greater than or equal to 1 is considered true, and you are performing a boolean comparison.

Said line calls place_meeting to check if the calling instance is colliding with obj_mosca. Since you are not using this in any if statement and not assigning the result to a variable, this line does nothing.

Next, your code includes an opening curly brace. However, because there is no if statement directly preceding it (because you ended the condition after obj_player and the place_meeting call is its own statement, not part of the condition), this block will always run.

Therefore, eat is always set to true.

Finally, you check whether place_meeting evaluates to false. This is because you merely used the function reference in the condition, rather than calling the function and passing parameters to it. Therefore, its numeric ID is evaluated, and unless it is 0 - and it is not, because function 0 is camera_create as far as I'm aware - the next line won't run.

If it was 0, however, eat would be set back to false.


With that out of the way, I suggest taking a close look at the manual page of place_meeting as it contains a proper usage example of the function.
 
Top