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

Legacy GM || Statement proper use?

J

Jdown79

Guest
Hey guys.
Building a platformer, and in my collision code its checking for a collision +1 with objWall.
I need it to check for two objects, and I figured the easiest way to do that was the OR statement.
But its disabled all collisions.
Is this not proper use?
Code:
if (place_meeting(x,y+1,(objWall || objWedge)))
    {
     vsp = keyJump * -jumpSpeed  
    }

//Horizontal Collision
if (place_meeting(x+hsp,y,(objWall || objWedge)))
    {
        while(!place_meeting(x+sign(hsp),y,(objWall || objWedge)))
            {  
                x += sign(hsp);
            }
        hsp = 0;      
    }



//Vertical Collision
if (place_meeting(x,y+vsp,(objWall || objWedge)))
    {
        while(!place_meeting(x,y+sign(vsp),(objWall || objWedge)))
            {  
                y += sign(vsp);
            }
        vsp = 0;      
    }
Thanks all
 

KhMaIBQ

Member
That function place_meeting only takes 1 object as its argument. You will need to do two place_meeting checks using the || (OR) expression. Demonstrated below...

Code:
if ( place_meeting( x, y+1, objWall ) || place_meeting( x, y+1, objWedge ) )
Another method to solve this is by using a parent object to represent all the objects the player can collide with. This is assuming the type of object being collided with doesn't matter. You would create another empty object that would then be assigned as the parent to all the child objects. By doing the following code...

Code:
if ( place_meeting( x, y+1, objClsnParent ) )
This would allow you to check for both objWall and objWedge at the same time if objClsnParent is both their parent. If you need a different action to occur depending on the collision object, then you can specify which one you need instead of using objClsnParent.

I hope this helps.
 
J

Jdown79

Guest
That actually makes so much more sense.
That was a silly mistake, I thought the statement could handle more.
I went with the parent approach, Thank you.
Now I wonder how to make it not stick into the "wedge" objects, gets stuck as it touches haha
 
J

JFitch

Guest
OR and AND only compare entire statements. You can't just use them the same way you would in spoken language.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
OR and AND only compare entire statements. You can't just use them the same way you would in spoken language.
Did you just bump two half-of-year old topics to share your wisdoms on binary operators?
 
Top