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

GML Problem with OR logic

B

Blaze Runner

Guest
Hi everybody. I'm nees some help wih this code:

Code:
_apo = obj_control.active_player_obj;

if  (place_meeting  (x, y + 32, _apo) || place_meeting  (x + 32, y, _apo)) {

        // do stuff

}

if !(place_meeting (x, y + 32, _apo) || place_meeting (x + 32, y, _apo)) {

        if obj_control.txt_enter != noone {
    
             instance_destroy (obj_control.txt_enter);
             obj_control.txt_enter = noone;
        
       }
    
}
In the second if, if !(A || B):
>> I want it to be TRUE only when A is FALSE AND B is FALSE (which means, when _apo is not colliding).

At the moment, it appears as always true, even when A is TRUE OR B is TRUE, since the debug_log gets written also when _apo should make B or A true.
I've also tried to write: if (!A && !B).

Probably is not the best use of collisions, but it was the only way I could make it work in my code (collision event didn't).
I guess it might have to do with place_meeting(), but I hope I'm missing something in the logic.

Please let me know what you think. Any insight is much appreciated.
Thank you!

Filippo
 
B

Blaze Runner

Guest
Thank you for the reply.

1 | 1 = 1
1 | 0 = 1
0 | 0 = 0
You mean like:

Code:
if (

(place_meeting (x, y + 32, _apo) == true || place_meeting (x + 32, y, _apo) == true) &&
(place_meeting (x, y + 32, _apo) == true || place_meeting (x + 32, y, _apo) == false) &&
!(place_meeting (x, y + 32, _apo) == false || place_meeting (x + 32, y, _apo) == false)

)
So your code should work... But why not just use an else branch?
Yes, I tried with an else, but it doesn't work.[/CODE]
 

TheouAegis

Member
I was just mapping out bools. Are you sure you actually typed the code correctly? I mean, you posted pseudocode. Are you sure you didn't leave the parentheses or exclamation mark out on accident in the original code?

Anyway, try

if !A && !B

If that doesn't work, then your problem lies elsewhere.
 
B

Blaze Runner

Guest
Ok, I post the complete code. I hope someone will help me understand. I'm becoming crazy. :)

Code:
with (obj_com_link) {
   
    _apo = obj_control.active_player_obj;
   
    if obj_control.change_turn {
       
         scr_restore_text_boxes ();
   
    }
       
    // Interazione con COM-LINK
    if (!obj_control.just_patched
    and (place_meeting (x, y + 32, _apo)
    or place_meeting (x + 32, y, _apo))) {
   
        if player_controlling == noone {
           
            // Evita ripetizione della text-box
            if obj_control.txt_enter == noone {
           
                scr_restore_text_boxes ();
                   
                obj_control.txt_enter = scr_text (obj_control.str_enter, 1,
                iso_to_scr_x (id.x, id.y),
                iso_to_scr_y (id.x, id.y) - 230, true);
               
            }
       
            if keyboard_check_pressed (vk_enter) {
           
                id.player_controlling = _apo;
               
                scr_restore_text_boxes ();
               
                obj_control.txt_patched = scr_text (obj_control.str_patched, 1,
                iso_to_scr_x (id.x, id.y),
                iso_to_scr_y (id.x, id.y) - 230, false);
               
                obj_control.txt_patched_by = scr_text (
                    string (obj_control.str_patched_by) +
                    string (_apo.player_id), 1,
                    iso_to_scr_x (id.x, id.y),
                    iso_to_scr_y (id.x, id.y) - 160, true
                );
               
                scr_broadcast_message ();
               
                obj_control.just_patched = true;        
               
            }
           
        } else if player_controlling != _apo {
       
            if obj_control.txt_remove == noone {
           
                scr_restore_text_boxes ();
               
                obj_control.txt_remove = scr_text (obj_control.str_remove, 1,
                iso_to_scr_x (id.x, id.y),
                iso_to_scr_y (id.x, id.y) - 230, false);
               
            }
           
            if keyboard_check_pressed (vk_backspace) {
           
                id.player_controlling = noone;
                instance_destroy (obj_control.txt_patched_by);
                scr_restore_text_boxes ();
                 
                obj_control.txt_unpatched = scr_text (obj_control.str_unpatched, 1,
                iso_to_scr_x (id.x, id.y),
                iso_to_scr_y (id.x, id.y) - 230, false);
               
                obj_control.just_patched = true;
               
            }
       
        }
       
    } else {
       
        show_debug_message ("sd");
        if obj_control.txt_enter != noone {
   
            instance_destroy (obj_control.txt_enter);
            obj_control.txt_enter = noone;
       
        }
   
    }
   
}
 
Last edited by a moderator:

nesrocks

Member
Try this
Code:
if (place_meeting (x, y + 32, _apo) || place_meeting (x + 32, y, _apo)) { }
else
{
  //your code
}
 

TheouAegis

Member
Well for starters the code is a weeee bit different here. Your code here is

if A and (B || C)
else

That else there is checking if !A or !(B||C). So maybe separate the two conditionals.

if A {
if B||C
else
}
 
B

Blaze Runner

Guest
I think it had to do with the fact that I had more than one obj_com_link instance in the room and that made the rest of the code work weirdly, since every object checked the condition (and of course when the player was near one of the cl, he was far from another).
Anyway, I found a workaround through another part of the code. Thank you a lot for your help guys!
 

TheouAegis

Member
Where was this code located by the way? If the code is in obj_com_link itself, you don't need to use obj_com_link at all anywhere in that code.
 
B

Blaze Runner

Guest
Where was this code located by the way? If the code is in obj_com_link itself, you don't need to use obj_com_link at all anywhere in that code.
The code is inside the step event of obj_control (which is the only one in the room).
 
Top