How do I change the state of a few objects.

Get help using Construct 2

Post » Tue Oct 28, 2014 5:29 am

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
B
10
S
4
Posts: 52
Reputation: 856

Post » Tue Oct 28, 2014 6:23 am

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.)
B
26
S
17
G
8
Posts: 323
Reputation: 6,021

Post » Tue Oct 28, 2014 6:57 am

that did it! thanks a ton man!
B
10
S
4
Posts: 52
Reputation: 856

Post » Tue Oct 28, 2014 11:08 am

No problem. Glad it worked out. :D
B
26
S
17
G
8
Posts: 323
Reputation: 6,021


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests