0 Favourites

How do I change the state of a few objects.

  • Hello.

    I'm working on an capture the flag like RTS were if you click the flag selected units will go to capture it.

    a flag will have a max number of carriers. Meaning if you have ten units selected but there are only five free spots on the flag. only the first five will first become unselected, then run to the flag to carry it.

    To achieve this I set the flag object with two variables. one called "maxcarry" and the other called "currentcarry". If currentcarry is less than maxcarry, The event would deselect then increase current by one. If I select one unit at a time then tell it to capture the flag. The method works. if there is a spot the unit will take it and if not it will stand still.

    However all units selected become unselected and go for the flag even if there is only one spot.

    How can I create a function/loop/event that will pick out the needed units, then send them to the flag in a what I would imagine would be a "first come first serve" style?

    Sorry I would attach a pic of the event, But I deleted it when I saw it did not work. it was just the condition that if currentcarry is less than max then deselect and go to the flag and increase current by one.

    Thanks

  • Hey Sir LoLz,

    Would something like this do what you're looking for?

    flagSlotsRemaining = maxcarry - currentcarry

    Event:

    * Pick selected units.

    * Loop - For each unit.

    * flagSlotsRemaining >= 1. // If one or more slots are remaining.

    Actions:

    * Call function "assignUnitTNextAvailableFlagSlot", Param 0 = unit.uid. //Or however you assign them.

    * Deselect unit.

    * recompute flagSlotsRemaining.

    To make the above a little cleaner, you could break the "flagSlotsRemaining >= 1" condition into a sub-event, and place all the actions on that sub-event. And for a further, though likely negligible, optimization the sub-event could have a companion ELSE sub-event that breaks out of the loop if there are no more slots. That way, if there is only one slot left, and you select 100 units, you only run 1 loop iteration instead of 100 iterations.

    You could also replace the "For each unit" loop with a "For each unit (ordered)" loop, and use the distance from the unit to the flag as the ordering formula. This would assign units to the flag, with priority going to the closest units first. (Closest may not always = shortest travel path in an RTS, but you might not want to compute a path length for all selected units just to start the loop.)

  • that did it! thanks a ton man!

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • No problem. Glad it worked out.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
313 26,491
Juryiel's avatar
Juryiel
Unread hot topic Locked topic
195 16,197
Ashley's avatar
Ashley Construct Team Founder
Unread hot topic
99 10,139
karshinkoff's avatar
karshinkoff