Tower Defense Tower Upgrades

Discussion in 'Programming' started by fireair, Dec 6, 2018.

  1. fireair

    fireair Member

    Joined:
    Jun 16, 2018
    Posts:
    11
    So I am making a tower defense game and I would like to have the towers be upgradeable the only real problem is I don't really remember/know how to make the upgrade button instances know which tower created them. I think it has something to do with making the instance create a local variable but I'm not sure. Help would be greatly appreciated.
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,342
    I don't quite understand what you're asking. But I see two possibilities. First, each tower creates its own upgrade button. In this case you can simply do:

    Code:
    
    ///whatever tower code creates the button
    var new_button = instance_create_layer....
    with (new_button) {
        owner = other.id;
    }
    
    ///example use in button
    with (owner) {
        upgrade = true;
    }
    
    
    If there's one upgrade button and you select the tower to upgrade, then you'd simply want to add the tower's instance id to a global variable. For example:

    Code:
    
    //some mouse event perhaps
    global.selected = instance_position(mouse_x, mouse_y, tower);
    
    ///example use in button
    with (global.selected) {
        upgrade = true;
    }
    
    
     
  3. fireair

    fireair Member

    Joined:
    Jun 16, 2018
    Posts:
    11
    the first one is what I was asking thanks very much
     

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