How do I select 1 unit at a time?

  • I'm talking about cloned versions of the same unit.

    I want it so that if I click on a unit it becomes selected (Instance variable "selected" = 1)

    Then if I click a cloned version of that same unit, I want the currently selected unit to be deselected (Variable "selected" = 0) and the new unit to become selected.

    The way I tried it didn't work, and I can't think of any other way to do it.

    Can anybody help me out?

    Thanks

  • variable selectedUID

    event

    on clicked objectX

    action

    set selectedUID = objectX.UID

    set objectX.selected = 1

    sub event

    pick all objectX

    pick objectX by evaluate where objectX.UID <> selectedUID

    action

    set objectX.selected = 0

  • Hey thanks for the response. I typed in the code and it isn't working. It might be because I'm not exactly sure what it is I'm looking at though and just typed it in wrong, I'm pretty new to this sort of thing.

    Anyone know if I did something wrong?

    Sorry I also should have mentioned that I wanted to make it so that if I clicked on nothing that it would deselect my current target.

    Thanks again

  • SelectedUID should be a global or local variable, not instance variable of sprite, then it would work.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • SelectedUID should be a global or local variable, not instance variable of sprite, then it would work.

    This

  • Ok now I understand whats happening

    Thanks for the responses!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)