| 12-19-2004, 10:08 PM | #1 |
I am not the best with loops, so I came accross a problem. I have a trigger that runs when a structure finishes building, and the trigger sums up all of the same type of structures' mana. Example: A farm is built with 6 mana. The lumber is set to 6. Another farm is built with 5 mana. The lumber is set to 11. Oddly, the trigger adds the 6 from the first farm and the sum of the two farms, for a grand total of 17. These are the two triggers: Code:
Citi Build
Events
Unit - A unit Finishes construction
Conditions
((Constructed structure) is Undead) Equal to True
((Constructed structure) is Undead) Equal to True
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Unit-type of (Constructed structure)) Equal to Small Home
Then - Actions
Set temp_citizens = (Random integer number between 1 and 6)
Unit - Set mana of (Constructed structure) to (Real(temp_citizens))
Trigger - Run Citi Update <gen> (ignoring conditions)
Else - Actions
Do nothing
Citi Update
Events
Conditions
Actions
Player Group - Pick every player in (All players matching ((((Matching player) controller) Equal to User) and (((Matching player) slot status) Equal to Is playing))) and do (Actions)
Loop - Actions
Set temp_population = (Units owned by (Picked player) matching ((((Matching unit) is A structure) Equal to True) and ((((Matching unit) is Undead) Equal to True) and (((Matching unit) is alive) Equal to True))))
Unit Group - Pick every unit in temp_population and do (Actions)
Loop - Actions
Set player_population[(Player number of (Picked player))] = (player_population[(Player number of (Picked player))] + (Integer((Mana of (Picked unit)))))
Player - Set (Picked player) Current lumber to player_population[(Player number of (Picked player))]
Unit Group - Remove (Picked unit) from temp_population |
| 12-19-2004, 10:47 PM | #2 |
Found it. Code:
Set temp_population = (Units owned by (Picked player) matching ((((Matching unit) is A structure) Equal to True) and ((((Matching unit) is Undead) Equal to True) and (((Matching unit) is alive) Equal to True)))) Code:
Set player_population[(Player number of (Picked player))] = (player_population[(Player number of (Picked player))] + (Integer((Mana of (Picked unit))))) To fix it simply do as such: Set player_population[(Player number of (Picked player))] = ((Integer((Mana of (Picked unit)) You were adding your new total to your old total. ;) |
| 12-20-2004, 12:44 AM | #3 |
Well, I found a different solution and was hoping no one responded, but you already did try. So I guess you earn the reputation point. |
| 12-20-2004, 12:52 AM | #4 |
Lol, there were many ways to fix it, what I gave was just one. Glad to see you give rep though, keep the faith. I would return the favor but I've maxxed out on my rep giving for the day. ;) Also, if you need any help with your project just let me know, I'd be more then happy to help. |
