• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Another Looping Problem

Status
Not open for further replies.
Level 4
Joined
Jul 14, 2012
Messages
100
[Solved] Another Looping Problem

EDIT: Nevermind!! I guess after toying around a bit I managed to figure out how to do it. Thanks to those who helped! Heres what it is now, so its solved.

  • count civ happiness
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 102, do (Actions)
        • Loop - Actions
          • Player Group - Pick every player in playingplayers and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Owner of village[(Integer A)]) Equal to (Picked player)
                  • (village[(Integer A)] is alive) Equal to True
                • Then - Actions
                  • Set stockhappiness[(Player number of (Picked player))] = ((stockhappiness[(Player number of (Picked player))] + villagehappiness[(Integer A)]) + 0)
                • Else - Actions
                  • Do nothing
              • Set civhappiness[(Player number of (Picked player))] = stockhappiness[(Player number of (Picked player))]
              • Multiboard - Set the text for (Last created multiboard) item in column 2, row (Player number of (Picked player)) to ((String(cities[(Player number of (Picked player))])) + Villages)
              • Multiboard - Set the text for (Last created multiboard) item in column 4, row (Player number of (Picked player)) to (String(civhappiness[(Player number of (Picked player))]))
      • For each (Integer A) from 1 to 16, do (Actions)
        • Loop - Actions
          • Set stockhappiness[(Integer A)] = 0
 
Last edited:
Level 4
Joined
Jul 14, 2012
Messages
100
[Solved]

EDIT:Nevermind!! I managed to figure it out on my own after toying with it enough.Theres what it is now.. but anyway this trigger is solved. Thanks to those who helped
 
Last edited:
Level 4
Joined
Jul 14, 2012
Messages
100
There are a total of 102 lands, and therefore 102 villages can exist. When a village is settled, it is labeled onto these lands in a unit array.

What i want this trigger to do, is keep the Multiboard accurate in displaying how much total happiness a player has. His total happiness would be calculated by combining all of his cities' individual happinesses together.

So if I had 3 cities, one with 72 Happiness, one with 25 Happiness, and one with 13 Happiness, my total happiness would be 72+25+13= 110 Happiness. So thats supposed to represent Civilization Happiness, and I want that to be displayed for each player in the multiboard. But I'm having trouble calculating this...
 
Level 16
Joined
Jun 24, 2009
Messages
1,409
Why don't you just make a variable of the starter number of villages and increase it by one when a village is settled? It's much more efficient.

You could do this much easier with Hashtables(don't ask me how, I only know 2D variables from Pascal and C ~.~).
 
Level 4
Joined
Jul 14, 2012
Messages
100
Why don't you just make a variable of the starter number of villages and increase it by one when a village is settled? It's much more efficient.

You could do this much easier with Hashtables(don't ask me how, I only know 2D variables from Pascal and C ~.~).

Not sure I understand what youre saying? Just count the number of villages and then multiply by a constant number to get civilization happiness?

Unfortunately I cannot do that, because that would be assuming each village had the same Happiness, which they dont. Each one is unique. However, what I did do below may be what you are saying, but I'm not sure.

In my trigger I counted the old happiness of each village, then the new happiness, to calculate the difference. Then I add that difference to another integer called the total difference. Then it loops to count all other villages' differences, and adds them to this. Then afterwards, it adds this total difference to civilization happiness, plus the number of cities owned. So i counted civilization happiness by multiplying the number of cities by its initial happiness(either 15 or 35, depending on game mode), then added the difference(which may or may not be positive).

To me, that method seems to make sense, but maybe I'm missing a piece of logic in there that makes the trigger count wrong. That, or, I had set up the arithmetic wrong, since it involves both addition and multiplication. But I haven't found where it might be miscalculated.
 
Level 4
Joined
Jul 14, 2012
Messages
100
No. I mean, I guess there wont be 102 settled villages at the start, will be?

Erm... Why don't you just set the civ happiness to the sum of the new village happinesses?

No, not 102 villages at start.

And because I dont know how to do that. Like how to add up all villages belonging to player's happinesses??

EDIT: OK i guess after fiddling around a bit I fixed it on my own. Thanks for helping though :D
 
Last edited:
Level 16
Joined
Jun 24, 2009
Messages
1,409
Hehe :)
I was about to make example triggers. Anyways, you should modify this part to that.

  • For each (Integer A) from 1 to Villages, do (Actions)
Set the variable "Villages" to the number of starting villages and add this little trigger.
  • Untitled Trigger 001
    • Events
      • (Event that starts the trigger[When a village settles])
    • Conditions
    • Actions
      • Set Villages=Villages+1
That's more efficient than starting with 102 already when there are only a few villages.
 
Status
Not open for further replies.
Top