1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Enemy Problems [SOLVED]

Discussion in 'Programming' started by Amoses, Jun 23, 2019.

  1. Amoses

    Amoses Member

    Joined:
    Jun 14, 2019
    Posts:
    48
    So, I am trying to make it so everytime my player left clicks the enemy, it does damage, and thats working. except for the fact that everytime i click, it does damage to every enemy spawned, and im not sure how to fix that. if somebody could help please let me know!
     
  2. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,221
    What have you got so far? Can you show us the code?
     
  3. Amoses

    Amoses Member

    Joined:
    Jun 14, 2019
    Posts:
    48
    its just, ```if mouse_check_button_pressed(mb_left) && position_meeting(mouse_x,mouse_y,oEnemy)
    with (oEnemy)
    hp -= 20;```
     
  4. TinyGamesLab

    TinyGamesLab Member

    Joined:
    Jun 21, 2018
    Posts:
    147
  5. Amoses

    Amoses Member

    Joined:
    Jun 14, 2019
    Posts:
    48
    this still makes no sense. i would just like a line of code(s) that would help my issue.
     
  6. TinyGamesLab

    TinyGamesLab Member

    Joined:
    Jun 21, 2018
    Posts:
    147
    If you read the tutorial you'll find exactly what you need while learning more about objects x instances, which is why you could not get the code to work in the first place.
    Read this part:
     
  7. Amoses

    Amoses Member

    Joined:
    Jun 14, 2019
    Posts:
    48
    that was the exact part i did read. but i still do not know how and where to use these things.
     
  8. Amoses

    Amoses Member

    Joined:
    Jun 14, 2019
    Posts:
    48
    i now have
    if instance_exists(oEnemy)
    var inst_enemy = instance_place(oEnemy.x,oEnemy.y, oEnemy)
    if mouse_check_button_pressed(mb_left) && position_meeting(mouse_x, mouse_y, oEnemy)
    inst_enemy.hp -= 10
    and its making it so not several enemys get attacked at once, but only one is able to be attacked and even if i click on a different one, the first one gets attacked
     
  9. TinyGamesLab

    TinyGamesLab Member

    Joined:
    Jun 21, 2018
    Posts:
    147
    Here you go:
    Code:
    var inst;
    inst = instance_place(mouse_x, mouse_y, oEnemy));
    if (mouse_check_button_pressed(mb_left) && inst != noone)
       {   
       inst.hp -= 20;
       }
    
     
  10. Amoses

    Amoses Member

    Joined:
    Jun 14, 2019
    Posts:
    48
    it says unexpected syntax error?
     
  11. Amoses

    Amoses Member

    Joined:
    Jun 14, 2019
    Posts:
    48
    i fixed the unexpected syntax, but it still doesnt work at all.
     
  12. Amoses

    Amoses Member

    Joined:
    Jun 14, 2019
    Posts:
    48
    i fixed it myself, nevermind.
     
  13. woods

    woods Member

    Joined:
    Jun 21, 2016
    Posts:
    223
    something like this....?

    in your original post...
    with (oEnemy)
    // this makes all instances of oEnemy tahe damage
    should be
    with(other)
    // this makes the one you are clicking on take damage
     
  14. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    823
    @Amoses
    You were close here:
    Change it to...
    Code:
    if (mouse_check_button_pressed(mb_left))
    {
        var inst = instance_position(mouse_x, mouse_y, o_enemy);
        if (instance_exists(inst))
        {
            inst.hp -= something;
        }
    }
     
    Last edited: Jun 27, 2019
  15. curato

    curato Member

    Joined:
    Jun 30, 2016
    Posts:
    424
    you could just make an event in the object for when it is clicked by the mouse and put an hp minus in there and bypass this issue.
     
    NoFontNL and woods like this.
  16. Amoses

    Amoses Member

    Joined:
    Jun 14, 2019
    Posts:
    48
    Code:
     wadiom [Code]
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice