cant get this to work

For questions about using Classic.

Post » Wed Nov 18, 2009 8:49 pm

delete formation group:

+for each formation
+formation uid = ship('idformation')
- set formation('ships') to ship.count

it works so far, it counts 5 and when a ship is destroyed it counts down
but it never reaching 0 , always stops at 1 ship even when all are destroyed

i checked the id's and they all match, why doestn't it count to 0?
B
2
G
3
Posts: 72
Reputation: 994

Post » Wed Nov 18, 2009 9:49 pm

When there are no ships left, the formation uid = ship('idinformation') condition returns false, since there are no ships, so it doesn't set the count that time. You'll have to add another event to account for that case.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Wed Nov 18, 2009 11:45 pm

thanx mipey for pointing that out,

i have fixed that by inverting the code, and it works now,
but ran in another problem when creating more formations

so this is what i got now
ships = 0 destroy formation

+for each formation sorted by formation UID
+ inverted | formation uid = ship('idformation')
- set "ships" to countmatching(ships)

so i thought countmatching would only count the ships for the current loop,
but instead adds to the total number of ships, any idea why this happens?
B
2
G
3
Posts: 72
Reputation: 994

Post » Thu Nov 19, 2009 8:53 am

Countmatching expression picks all selected instances. I don't think the ships were filtered at all, so it picked all. You can guess the outcome.

Try this... create a (global) variable named 'allships', that tracks the total number of ships (though that may not be necessary, if you use Ships.Count, but I'm not sure if that is influenced by selection).

then...

+for each formation sorted by formation.UID
+inverted | ship('idformation)=formation.UID //this should select all ships that are NOT in the current formation)
-set "ships" to 'allships'-countmatching(ship) // all ships minus ships not in current formation = number of ships in the formation

Empty formations should have 0. A bit roundabout, but this should work. Perhaps someone else has a more elegant solution. Also, try using Ship.Count instead of 'allships', if it is not influenced by selection.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Thu Nov 19, 2009 8:59 pm

nope, didnt work, all formations where constantly destroyed,

i also gave the ships an formation group pv at creation , sorted by that, but then it crashed when the last ship destroyed, i guess its that damn bug again, when no objects exist and you loop trough it it crashes,

how the hell do you check an object for to be zero when there has to be an object to count :roll:

ill go back to my first implementation that has some error,most are destroyed, some are left behind dont even know why, but im loosing to much time on this one,

anyway thanx for the help
B
2
G
3
Posts: 72
Reputation: 994

Post » Fri Nov 20, 2009 7:07 am

Eh, Sprite.Count works for me, so I don't really know what is up... maybe someone else can look into this problem?
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 8 guests