1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. NOTICE: We will be applying a Xenforo update on Tuesday 25th of February. This means that from approximately 10:00 to 14:00 BST the forums will be offline (or possibly longer). Sorry for the inconvenience! Official Announcement here.

GM:S 1.4 To address one of the many

Discussion in 'Programming' started by mafon2, Sep 13, 2016.

  1. mafon2

    mafon2 Member

    Joined:
    Sep 13, 2016
    Posts:
    18
    Ok, I'm sure it's trivial thing many of you struggled with.

    I'd like to make a block that crumbles, when contacting fallin player or special block.

    Here's the code:

    Code:
    if (place_meeting(x,y-Movable_block.speedY,Movable_block))
    {
            instance_destroy();
    }
    As you can see, it affects all of the Movable_blocks so it can work only with one of 'em per room. How do you adress the particular block the instance collides with?

    I tried juggling with "other" with no result. I would have wrote these lines in Movable_block, but due to their common parrent that deals with collisions it's a mess I can't walk through.
     
  2. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,846
    Hi and welcome to the GMC!

    I'm not sure which object is executing the code you just posted.
    Is it Movable_block that has to "crumble"?
    In that case, try:
    Code:
    with Movable_block
        if place_meeting(x, y + speedY, other)
            instance_destroy();
    Otherwise, try:
    Code:
    with Movable_block
        if place_meeting(x, y + speedY, other)
            with other
                instance_destroy();
    You might also be interested in reading up on instance_place.
     
  3. Oz Locke

    Oz Locke Guest

    What event is this in?
     
  4. mafon2

    mafon2 Member

    Joined:
    Sep 13, 2016
    Posts:
    18
    Thanks for the quick replies.

    The code is in obj_rubble (yeah, the names of instances lack unification). Obj_rubble should crumble if it's hit with something. For now the only things that are planned to hit it are either Player_char or Movable_block. Beforementioned code works fine with Player_char or single Movable_block, but doesn't work with multiple blocks, cause it gets speedY and position from all Movable_blocks instances.

    In perfect world it should be that Movable_block falls on obj_rubble and destroys it, while other Movable_block neatly minds its own business.

    I'll try the later code jo-thijs posted and report the situation.
     
    Last edited: Sep 13, 2016
  5. stainedofmind

    stainedofmind Member

    Joined:
    Jun 20, 2016
    Posts:
    705
    If you want to access specific instances of objects outside of collision events, you have to capture the instance ID when using collision functions, roughly as follows:

    Code:
    var inst = instance_place(x, y + 1, obj_solid);
    
    if (inst != noone)
    {
        with (inst)
        {
            instance_destroy(); // This would destroy the block the calling instance is "standing" on.
        }
    }
    
     
  6. mafon2

    mafon2 Member

    Joined:
    Sep 13, 2016
    Posts:
    18
    Jo-thijs, your solution works. Thank you.

    I didn't know there're "withs". And it's hard for me to understand the rules of scripting. I thought the problem was harder than it is...

    Stainedofmind, thank you too, it'll be helpful later. As I understand you suggest to use some kind of an additional "matte" to check the collision?

    P.S. I used to have an account on the old forum and drove some guy to glowing frustration with my questions.
     

Share This Page